BackupManager & BackupAgent in Android 2.2

夙愿已清 提交于 2019-12-20 04:56:11

问题


I've reviewed the docs and the sample BackupRestore app and written my own test app implementing android:backupAgent. I extended the BackupAgent class because my main concern is being able to backup data from a database. I can't seem to even make a simple proof-of-concept app work with this feature.

To make things exceptionally simple, I declared the android:backupAgent as MyBackupAgent in the manifest. I then created a class MyBackupAgent.java, extending BackupAgent. I then created overrides for the onBackup() and onRestore() methods within the MyBackupAgent class, just like in the examples and docs. I added a Log.i() call to the very beginning of each function so that I could identify within LogCat when the functions were being called. Likewise, I set breakpoints on both of these. I then went on to implement my code to backup the database.

I created an emulator image using 2.2w/Google API's and even added a gmail account under Accounts & Sync. Running through the adb commands to enable bmgr, backup the app, run the backup, uninstall the app, reinstall the app etc.... I never once get a message in the log file from the Log.i() command in either of the onBackup() or onRestore() functions.

I tried again on my Evo 4g running 2.2. Same result. It does not appear that the backup manager is calling the onBackup() and onRestore() functions in the MyBackupAgent class.

The only odd message I get in my logs is one from the BackupManagerService stating "Backup pass but e=true p=false", I believe in response to the ADB command to backup the app.

Any suggestions? Am I wrong to assume that a Log.i() statement in the onBackup() and onRestore() functions would show up in LogCat?


回答1:


The outputBackup pass but e=true p=false means the backup manager is enabled (e=true) but not provisioned (p=false).

It will only run backups if both of these conditions are met. So for some reason the backupmanager is not provisioned on your emulator image, after digging through the code I noticed it should get auto-provisioned during bootup (DefaultActivity)

I/ActivityManager(   73): Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10000000 cmp=com.android.sdksetup/.DefaultActivity } from pid 0

I just created a fresh emulator image, and it worked without problems there.




回答2:


I also tried to use the "new" Backup Manager Service and always got following error messages:

12-01 09:58:54.420: WARN/BackupTransportService(9965): Unknown package in backup request: @pm@
12-01 09:58:54.450: WARN/BackupTransportService(9965): Not ready for backup request right now: [OperationScheduler: enabledState=false lastSuccess=2010-10-07/09:33:51 moratoriumSet=2010-12-01/09:53:32 moratorium=1970-01-01/01:00:00 trigger=1970-01-01/01:00:00]
12-01 09:58:54.450: WARN/PerformBackupThread(9965): Backup pass unsuccessful, restaging

Does anybody know what this means???

If I change backup transport to local version with following command

adb shell bmgr transport android/com.android.internal.backup.LocalTransport

everything works well. So its not a problem of my code, I think...

Regards!




回答3:


Check your phone's settings. If the syncronization-service is disabled then backup via Data Backup API won't work.



来源:https://stackoverflow.com/questions/3790190/backupmanager-backupagent-in-android-2-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!