6

I want to know,

  1. What happens to app data/database files/ etc while moving app from internal storage to SD card and vice versa?

Also I have an app which is installed in external storage. Im upgrading the app. The latest version of the app has flag to restrict install only in internal storage.

  1. Will this latest app get installed in internal storage? Will the system automatically move the app data from external to internal or the data from previous installation is lost?
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
Karthik
  • 108
  • 1
  • 6

1 Answers1

3

Actually this does not seem a programatic question is more an Android OS question.

First. As developer you don't choose HOW your app is installed, but since Android 2.2 you can choose WHERE:

Existing applications that were built prior to API Level 8 will always install on the internal storage and cannot be moved to the external storage

Since android API 8:

android:installLocation
internalOnly: Install the application on internal storage only. This will result in storage errors if the device runs low on internal storage.

preferExternal: The android system tries to install the application on external storage. If that is full, the application is installed on internal storage.

auto: Let the Android system decide the best install location for the application. The default system policy is to install the application on internal storage first. If the system is running low on storage, the application is then installed on external storage.

As long as you programatically don't define the installation / moving process, Android operating system will take care of moving (if possible) from internal to external and viceversa. But as programmer you must be carefull with the type of app you are developing to know if you should or not allow this option

Warning: When the user enables USB mass storage to share files with a computer or unmounts the SD card via the system settings, the external storage is unmounted from the device and all applications running on the external storage are immediately killed.

What happens: As long as you don't decide, let's explain in a simple way. All files of the app are moved to sd card except one little pointer in the internal storage that tells the system where the app is located. (imagine if you format your SD card manually, then your phone won't know app has dissapeared) but if you unmount it phone won allow you to access.

Second Application updates will by default try to retain their install location, but application developers may change the installLocation field in an update. Installing an application with this new attribute on older devices will not break compatibility and these applications will be installed on internal storage only. That means, older data will be moved as long as the app remains with same identifier (and signature if market app).

Source / Source

ADVANTAGES / DISAVANTAGES

To keep / update your database files / configuration when upgrading your app check here and here

Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
  • Say the user has installed an app(which doesnt specify any install location) in external SD card(or moved to SD card). Now new update app has flag 'internalOnly' set. What happens to the app data? – Karthik Jul 17 '15 at 08:20
  • as I tell in last part *Installing an application with this new attribute on older devices will not break compatibility and these applications will be installed on internal storage only.* that means, **if the app is the same in the market** will be moved (thats why compatibility is not broken) – Jordi Castilla Jul 17 '15 at 08:22
  • I see that that after upgrade DB files and other files in app sandbox were lost. I could not figure out the reason. Only change I made related to this to introduce the flag internalOnly in my recent version. Any idea what could have gone wrong? Its a Samsung S5 device. – Karthik Jul 17 '15 at 09:43
  • it also happens when upgrading version but not changing `android:installLocation` ? – Jordi Castilla Jul 17 '15 at 10:09
  • Which database are you using? Check [this](http://stackoverflow.com/questions/5561725/update-application-android) or [this](http://stackoverflow.com/questions/8941662/keeping-the-same-sqlite-database-when-upgrading-and-android-app-from-lite-to-pro) answers – Jordi Castilla Jul 17 '15 at 10:10