tags:

views:

181

answers:

4

My app needs to save files that will range from about 2-20mb. When I tried to do this I was getting an OutOfMemoryException. I did some reading and it's looking like Android has a file size limit of 1mb. Is this correct? If so, is there a way around this limitation, other than splitting up every file into 1mb chunks?

A: 

I don't think that's accurate. The browser is an app, for example, but it can download files of arbitrary size. Are you sure this isn't an issue with your application? Have you checked to see that you actually have enough space left?

John Feminella
A: 

can you be more accurate...Are u making a server call??are you getting an error while parsing it or while getting the input stream.

Rahul
I am running it on the android emulator, not an actual device. My app downloads an xml file, parses it, stores the info in a custom serializable class, and writes it to a file using ObjectOutputStream.Parsing and storing it in the class works fine. It's only if I try to save the file I get problems. In fact, if I remove about 2/3 of the data from the class, it saves fine. I suppose that since the data is taking up a lot of space in memory as it is, saving the file might push it over the edge. Is there a way to increase the total allocated virtual memory of the app?
Sarevok
+3  A: 

The main application need to be small, like < 1 MB but you can save as many files as you want and as large as you want as long as you save them on the memory card. The available space that can be used for applications (and other secure data) is limited, usually under 128 MB. So basically you need to keep your application small and put the large part as an add-on or extra files that can be put on the memory card. If you application will use 20MB from the available space it will drastically reduce the number of people that will use it.

Adrian Faciu
+1  A: 

OutOfMemoryError means you exceeded the VM's RAM budget, which is 16MB or 24MB depending on what device you're on. It has nothing to do with file sizes.

The 1MB limit you're probably referring to is the maximum size of a compressed asset in an APK file.

Files in your app-private data area or on external storage can be as large as the filesystem will allow them to be. (I've heard the FAT32 implementation Android uses for SD cards has a 2GB limit for individual files, but don't remember the resolution of that thread.) Available disk space will likely be a larger concern.

Going back to your original problem, check the logcat output (via adb logcat or DDMS) to see if there are any messages from the garbage collector right before the OOM fired.

fadden