diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index cfa11213..1a638ae8 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -27,7 +27,8 @@ THE SOFTWARE.
android:installLocation="auto">
+ android:label="@string/app_name"
+ android:backupAgent="PreferencesBackupAgent">
@@ -94,6 +95,9 @@ THE SOFTWARE.
+
diff --git a/src/org/kreed/vanilla/PlaybackService.java b/src/org/kreed/vanilla/PlaybackService.java
index 7bfb769a..f7042b27 100644
--- a/src/org/kreed/vanilla/PlaybackService.java
+++ b/src/org/kreed/vanilla/PlaybackService.java
@@ -24,6 +24,7 @@ package org.kreed.vanilla;
import android.app.NotificationManager;
import android.app.Service;
+import android.app.backup.BackupManager;
import android.appwidget.AppWidgetManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
@@ -35,6 +36,7 @@ import android.database.ContentObserver;
import android.database.Cursor;
import android.media.AudioManager;
import android.media.MediaPlayer;
+import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
@@ -414,6 +416,9 @@ public final class PlaybackService extends Service implements Handler.Callback,
} else if ("headset_play".equals(key)) {
mHeadsetPlay = settings.getBoolean(key, false);
}
+
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO)
+ new BackupManager(this).dataChanged();
}
/**
diff --git a/src/org/kreed/vanilla/PreferencesBackupAgent.java b/src/org/kreed/vanilla/PreferencesBackupAgent.java
new file mode 100644
index 00000000..6e644340
--- /dev/null
+++ b/src/org/kreed/vanilla/PreferencesBackupAgent.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2011 Christopher Eby
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+package org.kreed.vanilla;
+
+import android.app.backup.BackupAgentHelper;
+import android.app.backup.SharedPreferencesBackupHelper;
+
+/**
+ * Saves application preferences to the backup manager.
+ */
+public class PreferencesBackupAgent extends BackupAgentHelper {
+ private static final String BACKUP_KEY = "prefs";
+
+ @Override
+ public void onCreate()
+ {
+ // This is the preference name used by PreferenceManager.getDefaultSharedPreferences
+ String prefs = getPackageName() + "_preferences";
+ addHelper(BACKUP_KEY, new SharedPreferencesBackupHelper(this, prefs));
+ }
+}