私はBackupAgentHelperAndroidOS2.2から新しいものを実装しています。
SharedPreferencesそれが機能するためには、バックアップしたいの名前を指定する必要があります。
public class MyPrefsBackupAgent extends BackupAgentHelper {
// The name of the SharedPreferences file
static final String PREFS = "user_preferences";
// A key to uniquely identify the set of backup data
static final String PREFS_BACKUP_KEY = "prefs";
// Allocate a helper and add it to the backup agent
void onCreate() {
SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS);
addHelper(PREFS_BACKUP_KEY, helper);
}
}
問題はPreferenceManager.getDefaultSharedPreferences()、アプリケーションでメソッドを使用して、デフォルトの共有設定インスタンスを取得することです。次に、そのファイルの名前を指定する必要があります。どうすればそれが何の名前かわかりますか?
(そして、なぜ彼らはDefaultSharedPreferencesバックアップを行うだけのヘルパーを提供しないのですか?)