Android and data storage space?

北城以北 提交于 2019-12-02 05:01:50

问题


Im wondering how much data storage is available for my application in android?

I need to cache lots of files, and i was thinking to store it inside the sharedpreferences, this way it gets deleted if the application is uninstalled. Afterall its just alot of cache files. I guess i could also use the SDCard, but than i dont have any controll of what the user does outside the application...

So, how many MB can my application steel from SharedPreferences when storing files ?


回答1:


If you are planning to store MBs of data then try to use the sdcard to avoid filling the often limited storage built into the phone especially on the G1.

If you do store data on the phone, each app has its own storage area which will also be deleted when the application is uninstalled.

See http://d.android.com/reference/android/content/Context.html#getDir(java.lang.String, int)

For cached files you can use File cacheDir = getCacheDir(); which returns the path to the application specific cache directory on the filesystem. These files will be ones that get deleted first when the device runs low on storage.

See http://d.android.com/reference/android/content/Context.html#getCacheDir() for more information




回答2:


What is the purpose of the caching you want to implement?

If you want to avoid downloading files from Internet multiple times, the SDCard or SQLiteDatabase should be good options, depending on the type of the files, you are working with. If you want to keep the files up in the memory (for example, you want to keep some decoded bitmaps in the heap), it will be best to implement your own Cache class.

SharedPreferences can be used only with some basic types (boolean, int, String, long, float) - so Parcelable can't be put in your app's preferences.

This would pose a problem for saving files there.



来源:https://stackoverflow.com/questions/1547103/android-and-data-storage-space

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!