How to store large amount of data

SDK Version: 

The internal storage of an android device is very limited, so if your application downloads or somehow generates a large amount of data to store, you should save it on the external storage, the sd card. Even 1mb of data takes much space compared to the whole internal capacity on most of the current devices. The sd card has a bigger magnitude, and it is even expandable.

Even when storing data on the sd card you should limit the space your application can use up. For example if you cache images for an application you should track the usage the images and when the sum size of them exceeds a given limit, delete the the oldest used one.

When developing for API Level 8 (2.2) the directory get by the getExternalFilesDir() method can be used for storing files. Files stored here will be automatically deleted when the application is uninstalled.

  1. getExternalFilesDir(null);

Below API Level 8 such dedicated directory is not available, only the sdcard directory can be queried by the getExternalStorageDirectory() method. It is recommended to store files in the /Android/data/
/files/ directory under the sd card, because for users with a 2.2 system this directory will be still deleted on uninstall.

  1. Environment.getExternalStorageDirectory().toString()+"/data/"+getPackageName()+"/files/";

Under 2.1 and below unfortunately all data created on the external storage will remain there, and there is not even a way for an app to run code on its own uninstall and do a cleaunup manually.