我想实现备份和恢复,但它不执行onBackup()
方法。我在清单文件中的代码是
<application android:icon="@drawable/icon" android:label="@string/app_name"
android:backupAgent="MyBackupAgent" android:restoreAnyVersion="true"
android:allowBackup="true" android:enabled="true">
<meta-data android:name="com.google.android.backup.api_key"
android:value="AEdPqrEAAAAIMiLZ2_rMQFv6Huz3BYWpuxfVoK68Wk0CFMiXwA" />
<activity android:name=".Splash" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
当Activity
我添加或更新我想要备份的任何项目时,我的代码是
BackupManager bm = new BackupManager(this);
bm.dataChanged();
在MyBackupAgent
我写的文件中
public class MyBackupAgent extends BackupAgent {
@Override
public void onBackup(ParcelFileDescriptor oldState, BackupDataOutput data,
ParcelFileDescriptor newState) throws IOException {
// TODO Auto-generated method stub
System.out.println("in MyBackupAgent");
}
@Override
public void onRestore(BackupDataInput data, int appVersionCode,
ParcelFileDescriptor newState) throws IOException {
// TODO Auto-generated method stub
}
}
但是在onBackup()
方法中它不打印任何东西,所以我怎样才能确定它是否进入了 onbackup 方法?