Retain app data after uninstall
Generally, as soon as the user uninstalls an application, application data is removed from the Android operating system.
This data includes the app data stored in the internal storage of the device, typically /data/data/{package_name}
and the application-specific directory on the external storage. Refer to the official documentation to learn more about storing data on Android.
In Android 10, a new Manifest flag called hasFragileUserData is added. Adding this flag to the manifest file gives end-users and option to retain application data even after the application is uninstalled.
Where to add this flag?
This flag should be added inside the application
tag of the Manifest file.
Before adding this flag to your Manifest file make sure you have bumped up the compileSdkVersion
and targetSdkVersion
to API level 29
How will it be shown to the users?
When uninstalling the application users will see a checkbox in which they can check and retain the application data on the device even after the application is uninstalled.
What data will be retained?
Data stored in the internal storage i.e. /data/data/{package_name}
and the data stored on the Application-specific storage on the external storage will not be removed from the device.