An Android app remembers its data after uninstall and reinstall

后端 未结 8 2178
半阙折子戏
半阙折子戏 2020-11-28 17:58

While developing an Android app targeting all versions above 4.1, I observed that uninstalling my app and installing it again does not clear its data.

The app is d

相关标签:
8条回答
  • 2020-11-28 18:27

    You should check your device's Backup and Reset settings, and turn off Automatic restore (when reinstalling an application, backed up settings and data will be restored.)

    Turning off auto-backup is different from the auto-restore. If you think it will be helpful to turn on auto-backup for your application do so. But if you think this will make end users who are not aware that the auto-restore feature of their device is turned on, feel free to turn it off.

    In my case, I turned off the allowBackup feature, but since I already had a backup of the previous version on the Cloud, it still kept on restoring.

    See image as reference for a Samsung device on Android 6.0. Other devices and versions may have a different screen. See image below.

    Automatic Restore Setting under Backup and Reset

    0 讨论(0)
  • 2020-11-28 18:29

    Just adding to this, we found that in Android 9 (on a HMD Nokia device) that the assets were held, even after deleting the app through the interface and through adb.

    The answer of adding:

    android:allowBackup="false" android:fullBackupOnly="false"

    Obviously, this is not a new answer - but an observation for people who were in the same position as us.

    0 讨论(0)
  • 2020-11-28 18:29

    Just change android:allowBackup="true" to android:allowBackup="false" in manifiest.xml. It will be worked.

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        <application
            android:allowBackup="false"
            android:icon="@mipmap/app_icon"
            android:label="@string/app_name"
            android:supportsRtl="true"
            android:theme="@style/AppTheme">
    </manifest>
    
    0 讨论(0)
  • 2020-11-28 18:30

    It's because Android 6 has automatic backup. You need to tune android:allowBackup and android:fullBackupContent in your manifest <application> tag if you don't want your data backed up or if you want to include or exclude some resources. It's not a bug.

    More about AutoBackup on Android here.

    0 讨论(0)
  • 2020-11-28 18:35

    I recently needed to take advantage of these features, I was able to uncover documentation and upon extensive testing this is what I have been able to deduce:

    Android:allowbackup - will backup local app data on the device it is located on.

    Android:fullBackupContent - is used in conjunction with Google's backup restore api and CAN be controlled via an xml file to specify what exactly to backup, as well as a BackupManager class you may implement for further control over the process.

    However the documentation states, and I have confirmed with testing, that a restore will only occur either when the device is restored and the restore app data process is triggered. OR it will also restore when the app is sideloaded through adb, which is what we do when we run the app for testing or debug on our devices through Android Studio. Note that if you set android:allowbackup but do not configure android:fullBackupContent with a Google api code then the apps data only gets stored locally, whereas if you configured it properly then if your app was backed up and you get a new device the apps data was stored on the cloud so it can be restored on a new device.

    0 讨论(0)
  • 2020-11-28 18:35

    If you are targeting android 10 then you have to put android:hasFragileUserData="true" in application tag of AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android">
      <application
        android:name=".MyApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:allowBackup="true"
        android:hasFragileUserData="true">
    
        .....
    
         </application>
    
     </manifest>
    

    android:hasFragileUserData is a new manifest setting (I’m guessing on ). “If true the user is prompted to keep the app’s data on uninstall”. This seems ripe for abuse, but I can see where it might be useful for some apps.

    See https://commonsware.com/blog/2019/06/06/random-musings-q-beta-4.html

    0 讨论(0)
提交回复
热议问题