22

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.

OBX
  • 6,044
  • 7
  • 33
  • 77
Leos Literak
  • 8,805
  • 19
  • 81
  • 156
  • Can you be specific what previous data do you get? – OBX Feb 05 '17 at 11:14
  • Database and shared preferences. I can see that there is no ormlite initialization. – Leos Literak Feb 05 '17 at 11:17
  • And only on devices from API 23 + right ? – OBX Feb 05 '17 at 11:17
  • Does this issue occur any device below marshmallow? – OBX Feb 05 '17 at 11:24
  • I just ran emulator for a tablet with SDK 18 and it worked as expected. Upgrade kept device previous data, fresh install (after app removal) had no data at all. Then I started emulator for another tablet with SDK 23 and it had no data. It really seems that the problem is local to my phone. – Leos Literak Feb 05 '17 at 11:24
  • Yes, I got it. Can you post your manifest as well. To confirm the issue :) – OBX Feb 05 '17 at 11:25
  • Added app section. Do you mean backup attributes? Strange is that I had several modifications so why concrete date is kept? – Leos Literak Feb 05 '17 at 11:28
  • 1
    hmm, I ll answer the cause of it! – OBX Feb 05 '17 at 11:28

6 Answers6

37

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 25MB , 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)

OBX
  • 6,044
  • 7
  • 33
  • 77
  • Great. I can see the app in Manage backups in the Drive but I cannot delete it. Can I configure Manifest via gradle that this property is off for debug release? – Leos Literak Feb 05 '17 at 11:57
  • Confirmed, setting to false helped. I tried to put resValue 'string', 'full_backup', 'false' in gradle and reference it within manifest: android:fullBackupContent="@string/full_backup, but this did not work and backup was loaded anyway. – Leos Literak Feb 05 '17 at 12:28
  • I did not understand it complete. Trying to disable backup while on debug builds? – OBX Feb 05 '17 at 12:31
  • Exactly. I want a production build be backed up, but debug build not. – Leos Literak Feb 05 '17 at 12:33
  • Why not set `android:allowBackup="false"` and set it to true, before building the release apk ? – OBX Feb 05 '17 at 12:33
  • Not very elegant and it is easy to commit it accidentally or forget to change it before build. – Leos Literak Feb 05 '17 at 12:36
  • Hmm, then in that case you should ask a new question with that specific problem I believe. I have not been to that specific problem. :/ regrets :/ – OBX Feb 05 '17 at 12:38
  • One inaccuracy about size limit of backup: 25MB for each application per one user/device. It means if user has 2 devices, then limit will be 25MB for each user's app per device. – ultraon Aug 15 '18 at 13:57
  • How do i let my app users decide, if they want to enable backup or not? Why is the preference of backup or not to backup done at compile time? Why doesnt google gives an option to let this be decided by the user of the app. What i am asking is let the dev decide what to backup and what to not backup, so that the app behaves as intended., BUT let the user of the app decide if this backup even happens or not. – ashishsony Sep 19 '18 at 14:30
  • Is it possible to clear/remove (not disable) the backup in any way? We are having some problems because of it specific to the beta testing process. – User Jun 17 '20 at 12:40
9
<application ...
    android:allowBackup="false"
    android:fullBackupContent="false"
    tools:replace="android:allowBackup"
</application>
Ashwin Khadgi
  • 292
  • 4
  • 12
7

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"
cakan
  • 2,099
  • 5
  • 32
  • 42
Vikash Bijarniya
  • 404
  • 4
  • 10
1

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

Dibzmania
  • 1,934
  • 1
  • 15
  • 32
0

i know this is not a perfect solution but its worked for me.

after uninstalling the specific app i switch off the device and switch on the device, Device OS not calling backup check from cloud

Mohd Qasim
  • 896
  • 9
  • 20
0

One way to clear the backup of the app is:

Clear that app data and its cache.

Note: This is a temporary solution as uninstalling and reinstalling the app would restore the backup automatically.

Deepanshu
  • 890
  • 5
  • 18