开发者

Data Backup into Google Servers using Android Backup Service in Android

Im trying to do the backing up of my application's data into the Google Servers..

For doing this I've implemented a BackupAgent in my code and I included this in the Android Manifest file and "Meta-data" ( Got after registered my Application's package with the Android Backup Service)

When I run the application to do the backup this is not performing the backup.. Im using Nexus one device (connected to WIFI also) .

Could any one please let me know why it is not calling my BackupAgent's onBackup() method?

Am I missing some thing, to include in the Android manifest file or some where in the program?


The below is my manifest file..

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="org.simpledatabackup"
      android:versionCode="1"
      android:versionName="1.0">

    <application android:icon="@drawable/icon" android:label="@string/app_name"
                 android:backupAgent="MyBackupAgent"
                 android:debuggable="true">


        <activity android:name=".SimpleDatabackup"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data android:name="com.google.android.backup.api_key"
                   android:value="AEdPqrEAAAAIZn2ysSLR5wNbcq1uaoWQO0HuipMetQENVTsilw" />

    </application>

    <uses-sdk android:minSdkVersion="8" />

</manifest> 

and the source file is

public class SimpleDatabackup extends Activity {

    private SharedPreferences myPrefs ;         // Shared Preferences

    BackupManager mBackupManager;


    /** Called when the activity is f开发者_如何学编程irst created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        myPrefs = this.getSharedPreferences("shared_prefs", MODE_WORLD_READABLE);

        SharedPreferences.Editor edit = myPrefs.edit();
        edit.putString("firstname", "uday") ;
        edit.putString("lastname", "kiran") ;
        edit.commit() ;

        mBackupManager.dataChanged();   



    }
}

My Backup Agent is some thing like this: I have not implemented the functionality inside is onBackup() and onRestore(). Once if it is called i will implement what ever i want..

public class MyBackupAgent extends BackupAgent {

@Override
public void onCreate() {

    System.out.println("In MyBackuAgent's onCreate() method");

}

@Override
public void onBackup(ParcelFileDescriptor arg0, BackupDataOutput arg1,
        ParcelFileDescriptor arg2) throws IOException {

    System.out.println("In MyBackuAgent's onBackup()");
    // TODO Auto-generated method stub

}

@Override
public void onRestore(BackupDataInput data, int appVersionCode,
        ParcelFileDescriptor newState) throws IOException {

}

}


In the application tag in the manifest include

android:allowBackup="true" 
android:restoreAnyVersion="true" 
android:backupAgent="<package>.MyBackupAgent"

Please follow the "Testing your BackupAgent" section to invoke the backup instantly for testing.

BackupManagerService schedules the backup regularly in hour interval after the datachanged call to backupmanager. [grepcode]

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜