How to prevent auto-backup of an Android app?
Solution 1
Since Android 6.0 (v 23) onward, Android introduced a new feature called Auto-backup for apps . What this does is, it performs a backup of certain files of an application to a user's Google drive. The list of files it updates include:
- Shared preferences files
- Files in the directory returned by
getFilesDir()
- Files in the directory returned by
getDatabasePath(String)
- Files in directories created with
getDir(String, int)
- Files on external storage in the directory returned by
getExternalFilesDir(String)
Now this line in the manifest.xml
is responsible for it :
android:allowBackup="true"
If you prefer to disable the backup, should you choose to set the value to false
.
Furthermore, the data backed up is in a 24 hour interval and Android uses the JobScheduler API for this purpose, so which means a user has no control over the process of data being transferred.
Also, the space for auto-backups is limited to 25
MB , and which is not counted against the user's space quota.
Also, you can set to <include>
and <exclude>
certain type of data being uploaded, for instance you may not need to save a user confidential data, so it is flexible for that as well, more info on that is available at : Android Auto Backup for Apps (100 Days of Google Dev)
Solution 2
<application ...
android:allowBackup="false"
android:fullBackupContent="false"
tools:replace="android:allowBackup"
</application>
Solution 3
Simply change
android:allowBackup="true"
to
android:allowBackup="false"
And if you are using any dependency, to override this property use
tools:replace="android:allowBackup"
android:allowBackup="false"
Solution 4
I had this same problem and really had to scratch my head because Google has not highlighted a subtle change in App backup feature.Starting from API level 23, all app data will be automatically backed up in Google drive. This data would be restored back when the app is installed back. So the data does not go away even when you uninstall the app.
Mostly your app manifest would have an entry like this -
android:allowBackup="true"
Change the value to false
or else follow the below link and configure an xml letting the backup service know what to backup and what not to.
https://developer.android.com/guide/topics/data/autobackup.html
Leos Literak
Java enthusiast (since 1996), author of www.abclinuxu.cz website (aka stackexchange for czech/slovak linux users), solution architect, developer ..
Updated on November 26, 2020Comments
-
Leos Literak over 3 years
I face very weird situation on certain device (Nexus 5x with Android 7): when I clean its data and uninstall it, then install it with Studio, the app is not unitialized but it uses data from 24th january! I tried the same procedure with a tablet and the app has no data.
I have repeated this procedure many times, I cleaned my project, rebuilt it multiple times and it always starts with 24th january data (both database and shared prefs).
I even tried adb shell and run as to clean up data:
bullhead:/data/data/lelisoft.com.lelimath.debug $ ls -l databases/ total 232 -rw-rw---- 1 u0_a259 u0_a259 98304 2017-02-05 11:03 lelimath.sqlite -rw------- 1 u0_a259 u0_a259 16928 2017-02-05 11:03 lelimath.sqlite-journal
I deleted them and the app seemed empty - until I deleted it and installed again - 24th january was back.
This is a log how it starts:
$ adb shell am start -n "lelisoft.com.lelimath.debug/lelisoft.com.lelimath.activities.DashboardActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -D Waiting for application to come online: lelisoft.com.lelimath.debug | lelisoft.com.lelimath.debug.test I/InstantRun: Instant Run Runtime started. Android package is lelisoft.com.lelimath.debug, real application class is lelisoft.com.lelimath.helpers.LeliMathApp. D/l.c.l.h.LeliMathApp: onCreate() D/l.c.l.h.BalanceHelper: Current points balance: 234
This is a location of a database, got from a debugger:
/data/user/0/lelisoft.com.lelimath.debug/databases/lelimath.sqlite
Gradle:
android { signingConfigs { } compileSdkVersion 24 buildToolsVersion "23.0.3" defaultConfig { applicationId "lelisoft.com.lelimath" resValue 'string', 'app_name', 'LeliMath' minSdkVersion 16 targetSdkVersion 24 versionCode 300 versionName '3.0.0' resValue "string", "app_build_number", getDate(); resValue "string", "app_version", versionName; } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } debug { applicationIdSuffix ".debug" resValue 'string', 'app_name', 'LeliMath DEV' } }
Manifest portion:
<application android:name=".helpers.LeliMathApp" android:allowBackup="true" android:fullBackupContent="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" tools:ignore="GoogleAppIndexingWarning">
I do not want o factory reset my phone to get rid off this data. I do not think that this data is in my build. I have not added them and the app in the tablet was empty when installed.