48

On my Nexus 5 running Android M Developer Preview 2, when uninstalling/reinstalling an app, the device is retrieving shared preferences I stored long ago, for instance a boolean isFirstLaunch.

The only way to clear these is to do it manually from the device settings.

Is there any change in shared preferences behavior on Android M? I can't find any documentation regarding this.

Or maybe the Android M Preview 2 ROM has a bug...

nios
  • 1,153
  • 1
  • 9
  • 20
  • I cannot reproduce this behavior on a Nexus 5 running MNC v2. Uninstalling an app (whether via drag-and-drop from the home screen launcher or `gradle uninstallDebug`) and reinstalling the app (whether via Android Studio or `gradle installDebug`) clears any existing preference data. If you get a chance and could write up your exact steps for reproducing this, I would be most interested -- thanks! – CommonsWare Aug 15 '15 at 15:22
  • 2
    I realized that I had the `android:allowBackup` parameter to `true` in the manifest. Apparently, on recent version of Android Studio/build tools, it is automatically added to the manifest. If you set it to `false`, the problem goes away, as indicated in my comment of the accepted answer. Hope this helps ! – nios Aug 17 '15 at 09:16
  • I did a few hours to resolve this problem, because the app restore their old data. i got weird result. – raditya gumay May 20 '16 at 06:13

3 Answers3

80

That is because Android M will feature Automatic Backups (old link).

Extract:

The automatic backup feature preserves the data your app creates on a user device by uploading it to the user’s Google Drive account and encrypting it. There is no charge to you or the user for data storage and the saved data does not count towards the user's personal Drive quota. During the M Preview period, users can store up to 25MB per Android app.

Knossos
  • 15,802
  • 10
  • 54
  • 91
  • 10
    Thanks for your answer ! I will set the `android:allowBackup` manifest attribute to false while I figured how to properly use the backup feature. – nios Aug 14 '15 at 13:22
  • I have encountered this issue too. It's ok when android:allowBackup is false. Did you find any other solution? – Orcun Sevsay Nov 13 '15 at 14:53
  • 1
    Google rotted the link, I think it can be found here now: https://developer.android.com/guide/topics/data/autobackup.html – nmr Dec 12 '16 at 22:30
13

Even already answered this question above, not mentioned the actual solution to avoid the auto backup even after uninstalling the app.

As per official, doc says to avoid auto backup need to do <application android:allowBackup="false"> in the Manifest file under application tag.:

Enabling and disabling backup Apps that target Android 6.0 (API level 23) or higher automatically participate in Auto Backup because of the android:allowBackup attribute defaults to true. To avoid any confusion, you should explicitly set the attribute in your manifest as follows:

<manifest ... >
    ...
    <application android:allowBackup="false" ... >
        ...
    </application>
</manifest>

You might want to disable backups by setting this to false if your app can recreate its state through some other mechanism or when your app deals with sensitive information that should not be backed up

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
7

Open settings -> Backup & reset -> automatic restore -> off if is on then app cache and database will be restore.

Tabassum Latif
  • 247
  • 2
  • 15