开发者

How does a BackupAgent work?

开发者 https://www.devze.com 2022-12-15 17:07 出处:网络
I\'m looking at AndroidManifest files and I see entries for android:backupAgent and according开发者_如何学运维 to the Documentation android:backupAgent is

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?


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
 */


All I can offer is the source code for android.app.BackupAgent 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
*/

and:

/** @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.

0

精彩评论

暂无评论...
验证码 换一张
取 消