How does a BackupAgent work?

I'm looking at AndroidManifest files and I see entries for android:backupAgent and according to the Documentation android:backupAgent is

The name of the class implementing BackupAgent to manage backup and restore of the application's settings to external storage.

But I can't find a BackupAgent interface or any other documentation. Can someone point me in the right direction?

Asked by: Gianna756 | Posted: 24-01-2022

Answer 1

BackupAgent's API is not solidified yet, so it's a hidden class. You can check it out on Android's git, where there is this comment:

 * This is the central interface between an application and Android's
 * settings backup mechanism.
 * @hide pending API solidification

Answered by: Robert851 | Posted: 25-02-2022

Answer 2

All I can offer is the source code for and the source code for android.backup.BackupManager.

BackupAgent is an abstract class and according to the javadoc in the source it "is the central interface between an application and Android's settings backup mechanism." It has abstract onBackup() and onRestore() methods.

There is also BackupManager. The javadoc says "BackupManager is the interface to the system's backup service. Applications simply instantiate one, and then use that instance to communicate with the backup infrastructure." It has a dataChanged() method to call to schedule a backup and a beginRestoreSession() method to start a restore.

Now, the interesting things in the code for BackupManager are:

* @hide pending API solidification


/** @hide TODO: REMOVE THIS */
public static final boolean EVEN_THINK_ABOUT_DOING_RESTORE = true;

So it seems that this is still a work in progress and the EVEN_THINK_ABOUT_DOING_RESTORE member variable is an easy way to disable backup functionality. My guess is that it is disabled in production Android builds.

Answered by: Darcy761 | Posted: 25-02-2022

Similar questions

android - Looking for a BackupAgent (for a sqlite database) example

I see several examples here, but none speak to backing up SQLite databases specifically, does anyone have a sample of doing this?

cloud - Can't get BackupAgent to work when reinstall from Android Market

I have implemented the BackupAgentHelper according to the documentation, including backward compatibility for 1.6, to backup all my SharedPreferences. It is working just fine when testing it in emulator Android 2.2 and when running on my device, which runs stock Android 2.3.3, via USB. In both these test cases I issue: adb shell bmgr run, which triggers the backup. However, wh...

android - Is backupAgent attribute necessary for application element?

The documentation for AndroidManifest.xml says: There is no default. The name must be specified. on this page: But I have the code for a working sample project that does not include it. What gives?

android - onRestore not invoked for my custom BackupAgent

There are some data in my Android app that I would like to backup and restore. For that purpose I have created a custom implementation of BackupAgent. In my manifest in have included the backup agent as you can see below <manifest xmlns:android="" android:installLocation="auto" package="com.myapp" android:versionCode="14" andr...

android - BackupAgent has one cloud backup per Device?

I have one Google Account with many devices attached (look in settings of market website). When I backup my App with BackupAgent and wipe another device, the wiped device doesn't restore anything. If I save a text "Nexus S" on one device and "Nexus One" on another one, they restore "Nexus S" and "Nexus One". It is the normal behavior? Can we use BackupAgent with an unique backup as iClou...

android - BackupAgent fails after package rename

I have an app, that uses backup feature. This is line from my manifest: android:backupAgent="my.package.backup.BackupAgent" It works fine in current version. But now I want to move the same BackupAgent to another package my.package.other.backup.package. When I install new version to new device, it still works fine. But when I try to install new version ove...

android - BackupAgent not working in Jelly bean. A bug in Jelly bean?

I am testing the sample code BackupRestore from Android SDK 16 (with my own key), but it does not work. The exactly same code works for ICS and GB. When I reinstall the app, I got 09-08 23:55:27.159: I/BackupManagerService(149): New app never backed up; scheduling When opening the app after reinstall, I got 09-08 23:53:48.240:...

Android BackupAgent not working

I am trying to get the BackupAgent working but I can't get it to work. Here is my sample code: The layout is just a TextView and a Button. MainActivity: ... public static final String PREF_NAME = "TestPref"; private static final String TEST_KEY = "TEST"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.a...

android - BackupAgent subclass used for automatic restore but not manual restore

I've set up the Android Backup Service in my app using a custom class that extends BackupAgentHelper ... it basically looks like this: public class MyBackups extends BackupAgentHelper { @Override public void onCreate() { Log.d("MyBackups", "creating backup class"); this.addDefaultHelper(); String defaultSharedPrefsName = this.getPackageName() + "_preferences"; Share...

android - BackupAgent - Unable to restore package

I have an old application that I've been updating by adding android backup service. I use a BackupAgent to take the content from a table in my SQLite database and write it to a JSON file and then upload it. I've used as reference when coding this. It works great on my Ne...

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android