Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android M weird shared preferences issue

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...

like image 339
nios Avatar asked Aug 14 '15 12:08

nios


People also ask

What does Android shared preferences do?

Shared Preferences is the way in which one can store and retrieve small amounts of primitive data as key/value pairs to a file on the device storage such as String, int, float, Boolean that make up your preferences in an XML file inside the app on the device storage.

Can an app have multiple shared pref files?

Yes you can maintain as many shared preference files for an app as you can.

Can we use SharedPreferences in Android?

Android App Development for BeginnersShared Preferences allow you to save and retrieve data in the form of key,value pair. In order to use shared preferences, you have to call a method getSharedPreferences() that returns a SharedPreference instance pointing to the file that contains the values of preferences.

What is the maximum number of shared preferences you can create in Android?

there is no limit in Shared Preference.


2 Answers

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.

like image 151
Knossos Avatar answered Oct 18 '22 13:10

Knossos


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

like image 26
Shailendra Madda Avatar answered Oct 18 '22 13:10

Shailendra Madda