Add self-restore capability to Backup/Restore sample app
The Backup/Restore sample application now provides a "restore my own last-known-good data" button. When it is clicked the app will run the standard public BackupManager.requestRestore() operation. (This was the one aspect of the public API that was not previously exercised by the sample app.) Change-Id: I8abcfbad4b27b35fe9fafbbb97f89bac1d7a668c
This commit is contained in:
@@ -10,4 +10,6 @@ LOCAL_PACKAGE_NAME := BackupRestore
|
||||
|
||||
LOCAL_SDK_VERSION := current
|
||||
|
||||
LOCAL_PROGUARD_FLAG_FILES := proguard.flags
|
||||
|
||||
include $(BUILD_PACKAGE)
|
||||
|
||||
3
samples/BackupRestore/proguard.flags
Normal file
3
samples/BackupRestore/proguard.flags
Normal file
@@ -0,0 +1,3 @@
|
||||
-keepclassmembers class com.example.android.backuprestore.BackupRestoreActivity {
|
||||
public void onRestoreButtonClick(android.view.View);
|
||||
}
|
||||
@@ -16,58 +16,72 @@
|
||||
|
||||
<!-- Layout description of the BackupRestore sample's main activity -->
|
||||
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent">
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
<ScrollView
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_weight="1">
|
||||
|
||||
<TextView android:text="@string/filling_text"
|
||||
android:textSize="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<RadioGroup android:id="@+id/filling_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:orientation="vertical">
|
||||
<TextView android:text="@string/filling_text"
|
||||
android:textSize="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<RadioButton android:id="@+id/bacon"
|
||||
android:text="@string/bacon_label"/>
|
||||
<RadioButton android:id="@+id/pastrami"
|
||||
android:text="@string/pastrami_label"/>
|
||||
<RadioButton android:id="@+id/hummus"
|
||||
android:text="@string/hummus_label"/>
|
||||
<RadioGroup android:id="@+id/filling_group"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
</RadioGroup>
|
||||
<RadioButton android:id="@+id/bacon"
|
||||
android:text="@string/bacon_label"/>
|
||||
<RadioButton android:id="@+id/pastrami"
|
||||
android:text="@string/pastrami_label"/>
|
||||
<RadioButton android:id="@+id/hummus"
|
||||
android:text="@string/hummus_label"/>
|
||||
|
||||
<TextView android:text="@string/extras_text"
|
||||
android:textSize="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
</RadioGroup>
|
||||
|
||||
<CheckBox android:id="@+id/mayo"
|
||||
android:text="@string/mayo_text"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView android:text="@string/extras_text"
|
||||
android:textSize="20dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<CheckBox android:id="@+id/tomato"
|
||||
android:text="@string/tomato_text"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<CheckBox android:id="@+id/mayo"
|
||||
android:text="@string/mayo_text"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</LinearLayout>
|
||||
<CheckBox android:id="@+id/tomato"
|
||||
android:text="@string/tomato_text"
|
||||
android:layout_marginLeft="20dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
</ScrollView>
|
||||
</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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user