Are Internal Storage Files Deleted on App Update?

回眸只為那壹抹淺笑 提交于 2019-12-04 07:40:36

Internal files are removed only if you uninstall and reinstall. An upgrade will not remove internal files -- and it shouldn't. Consider that if it did that, your database would be removed for every upgrade as well.

You will need to add an additional check.

For reference, the following documentation explains this in a roundabout way:

Storage Options

Note that the first paragraph:

Android provides several options for you to save persistent application data.

(emphasis added)

Further down under Internal Storage it then says

When the user uninstalls your application, these files are removed.

By omission I conclude that since these options are "persistent" and it's only explicitly stated that the files will be removed on uninstall, that an upgrade will retain those files.

I've never seen an internal file removed during upgrade, so experientially, this holds true as well.

For what it's worth, if the file you have in raw is read-only, you don't even need to copy it. openRawResource() will give you an InputStream and allow you to access it as any other file. Internally, it's just that: A file.

Copying to external storage isn't a good alternative as the user (and in earlier Android versions, any other app) can access, delete or modify that file.

Uninstall will only remove internal files bundled with the application, folders create in the external storage will not be deleted when uninstall. for database, the database will be deleted when uninstall but will remain for updated application.

Still on the database, its depends on the way the developer built the application, if there is a change of database version, there can be a replace or a complete removal of the database.

Sipty

By using external storage, i.e. /sdcard/, your data will not be deleted, even when the app's being uninstalled.

Regarding internal storage: The question has been asked before: Android Internal Storage when updating application

And lastly, I would not leave anything to chance -- always make sure to check!

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