5

I'm having this same problem - as found in the google developer group. I quote what it is a very detailed explanation by Chris Grebeldinger (original author).

"In the documentation: http://developer.android.com/guide/topics/data/backup.html#Testing

It recommends testing backup/restore of your application by:

  1. installing your app
  2. make sure backup/restore is enabled
  3. changing some data and calling dataChanged()
  4. forcing bmgr to run a backup pass
  5. uninstall the app
  6. re-install the app and check if your data was restored

All seems well until step 4, when I see this in the log:

V/BackupManagerService( 306): removePackageParticipantsLocked: uid=10078 #1 V/BackupManagerService( 306): Removing backed-up knowledge of com.example.app

And then for step 5:

V/BackupManagerService( 306): restoreAtInstall pkg=com.example.app token=21 V/BackupManagerService( 306): No restore set -- skipping restore

So apparently backed up data is destroyed when an app is uninstalled, which means the official testing workflow can't possibly work right? What's the best way to test this?"

Has anybody managed to run and test this sample correctly?

A-Sharabiani
  • 17,750
  • 17
  • 113
  • 128
lblasa
  • 6,284
  • 4
  • 27
  • 29
  • I was also able to get it working on an old device by using LocalTransport. See my answer here: https://stackoverflow.com/questions/48873335/backupagenthelper-onrestore-not-getting-called/48876498#48876498 – live-love Feb 20 '18 at 02:54

2 Answers2

2

Thanks again to Chris Grebeldinger which kindly answered my reply to his original post in the google android developer group.

How it does work:

  • Install the app in device A.
  • Set any data or preferences in device A.
  • Force a backup on device A. (Using adb shell bmgr backup [app_name], adb shell bmgr run).
  • Grab a second device B.
  • Perform a factory reset on device B.
  • Once reset, install the app again.
  • The restore operation should be successful.

What annoys me is that the "steps" as shown on the Google Android documentation which appear to be quite detailed decided to omit what it appears to be a necessary and compulsory steps.

As Chris mentioned on his reply, I hope this helps other people who find the same problem.

Thanks.

EDIT:

After further testing with different devices, it appears that the whole backup/restore process can vary from manufacturer and device. I could test the sample app using Google's document approach i.e. by uninstalling and installing using a nexus 7 - just by a coincidence. So, my advice would be not to expect the same behaviour and consistency during your tests.

lblasa
  • 6,284
  • 4
  • 27
  • 29
  • 2
    I could get this working all on a single device. Install App, Set Data, Force backup. Perform Factory reset. Install App again. Restore should be successful. – barkside Jun 30 '14 at 15:40
  • Tried this on a Nexus 5 running Lollipop however it still doesn't restore my data @barkside. Will try later switching between device – StuStirling Jan 07 '15 at 16:58
  • 2
    It will not work without factory reset? It needs only re-install when try to restore data on same device. – Vitaliy L May 19 '15 at 13:38
2

Try using the emulator for testing purposes. Nexus 5 with API 22 worked for me just by uninstalling and installing the app.

Full process:

  1. Enable backup by adb: bmgr enable true
  2. Set local transport: bmgr transport android/com.android.internal.backup.LocalTransport
  3. Run your app and prepare for backup
  4. Run backup: bmgr backup <package> & bmgr run
  5. Uninstall app from emulator
  6. Install the app again - restore should happen automatically

Tip: lookup logcat for "backup" activities

Sam Van Kooten
  • 324
  • 1
  • 11
Kamil Seweryn
  • 2,072
  • 2
  • 17
  • 23