Merge "Add self-restore capability to Backup/Restore sample app"

This commit is contained in:
Chris Tate
2010-11-18 12:48:45 -08:00
committed by Android (Google) Code Review
5 changed files with 83 additions and 43 deletions

View File

@@ -10,4 +10,6 @@ LOCAL_PACKAGE_NAME := BackupRestore
LOCAL_SDK_VERSION := current
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
include $(BUILD_PACKAGE)

View File

@@ -0,0 +1,3 @@
-keepclassmembers class com.example.android.backuprestore.BackupRestoreActivity {
public void onRestoreButtonClick(android.view.View);
}

View File

@@ -16,11 +16,16 @@
<!-- Layout description of the BackupRestore sample's main activity -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
<ScrollView
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
android:layout_height="fill_parent"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
@@ -71,3 +76,12 @@
</LinearLayout>
</ScrollView>
<Button android:id="@+id/restore_button"
android:text="@string/restore_text"
android:onClick="onRestoreButtonClick"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="0" />
</LinearLayout>

View File

@@ -23,4 +23,6 @@
<string name="extras_text">Extras:</string>
<string name="mayo_text">Mayonnaise\?</string>
<string name="tomato_text">Tomato\?</string>
<string name="restore_text">Restore last data</string>
</resources>

View File

@@ -18,8 +18,10 @@ package com.example.android.backuprestore;
import android.app.Activity;
import android.app.backup.BackupManager;
import android.app.backup.RestoreObserver;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
@@ -249,4 +251,21 @@ public class BackupRestoreActivity extends Activity {
mBackupManager.dataChanged();
}
/**
* Click handler, designated in the layout, that runs a restore of the app's
* most recent data when the button is pressed.
*/
public void onRestoreButtonClick(View v) {
Log.v(TAG, "Requesting restore of our most recent data");
mBackupManager.requestRestore(
new RestoreObserver() {
public void restoreFinished(int error) {
/** Done with the restore! Now draw the new state of our data */
Log.v(TAG, "Restore finished, error = " + error);
populateUI();
}
}
);
}
}