Android和数据存储空间?
我想知道我的 Android 应用程序有多少数据存储可用?
我需要缓存大量文件,并且我正在考虑将其存储在共享首选项中,这样如果卸载应用程序,它就会被删除。毕竟它只是很多缓存文件。我想我也可以使用 SDCard,但是我无法控制用户在应用程序之外执行的操作...
那么,在存储文件时,我的应用程序可以从 SharedPreferences 中获取多少 MB 的数据?
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 ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您打算存储 MB 的数据,请尝试使用 SD 卡,以避免填满手机内置的通常有限的存储空间,尤其是在 G1 上。
如果您确实在手机上存储数据,则每个应用程序都有自己的存储区域,当卸载应用程序时,该存储区域也会被删除。
请参阅 http://d .android.com/reference/android/content/Context.html#getDir(java.lang.String, int)
对于缓存文件,您可以使用
文件cacheDir = getCacheDir();
它返回文件系统上应用程序特定缓存目录的路径。当设备存储空间不足时,这些文件将首先被删除。
请参阅 http://d.android.com/reference/android /content/Context.html#getCacheDir() 了解更多信息
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
您想要实现的缓存的目的是什么?
如果您想避免多次从 Internet 下载文件,SDCard 或 SQLiteDatabase 应该是不错的选择,具体取决于您正在使用的文件类型。
如果你想将文件保留在内存中(例如,你想在堆中保留一些解码的位图),最好实现你自己的 Cache 类。
SharedPreferences
只能与一些基本类型(boolean、int、String、long、float
)一起使用 - 因此Parcelable
不能放入您的应用程序的首选项。这会给在那里保存文件带来问题。
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
) - soParcelable
can't be put in your app's preferences.This would pose a problem for saving files there.