How to prevent automatic backup of Android application?

I am faced with a very strange situation on a specific device (Nexus 5x with Android 7): when I clean its data and delete it and then install it using Studio, the application is not unified, but it has been using data since January 24th! I tried the same procedure with the tablet and the application has no data.

I repeated this procedure several times, I cleaned my project, rebuilt it several times and always started data from January 24th (both databases and general prefs).

I even tried the adb shell and started data cleansing:

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 uninstalled them, and the application seemed empty - until I uninstalled it and installed it again - January 24th returned.

This is the magazine 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/lclhLeliMathApp: onCreate() D/lclhBalanceHelper: Current points balance: 234 

This is the location of the database received from the 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' } } 

Part of the manifest:

 <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 need o factory reset my phone to get rid of this data. I do not think this data is in my assembly. I did not add them, and the application on the tablet was empty during installation.

+7
java android android-manifest android-jobscheduler
source share
2 answers

Starting with Android 6.0 (v 23), Android has announced a new Auto Backup feature for apps . What it does is, it backs up certain application files to a Google user drive. List of files that it updates:

  • Common settings files
  • Directory files returned by getFilesDir()
  • Files in the directory returned by getDatabasePath(String)
  • Files in directories created using getDir(String, int)
  • Files on external storage in the directory returned by getExternalFilesDir(String)

Now this line in manifest.xml is responsible for it:

 android:allowBackup="true" 

If you prefer to disable the backup, you should set it to false .

In addition, data backups are in a 24-hour interval, and for this purpose Android uses the JobScheduler API, so this means that the user does not control the data transfer process.

In addition, the automatic backup space is limited to 25 MB and is not taken into account in the user space quota.

In addition, you can set <include> and <exclude> certain type of downloaded data, for example, you may not need to save confidential user data, so this is also quite flexible information. Available at: Android Auto Backup for Applications (100 days Google Dev)

+12
source share

I had the same problem, and I really had to scratch my head because Google did not highlight the subtle change in the application backup function. Starting from API level 23, all application data will be automatically copied to Google Drive. This data will be restored when the application is installed back. Thus, the data does not disappear even when the application is deleted.

Basically, your application manifest will have this entry:

 android:allowBackup="true" 

Change the value to false or follow the link below and configure xml so that the backup service will know what to do with the backup and what not.

https://developer.android.com/guide/topics/data/autobackup.html

+1
source share