Android 2.2 Backup dei dati: come DefaultSharedPreferences di backup?
-
08-10-2019 - |
Domanda
Io sono l'attuazione del nuovo BackupAgentHelper
da Android OS 2.2.
Per farlo funzionare è necessario fornire il nome del SharedPreferences
che si desidera effettuare il backup:
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);
}
}
Il problema è che io uso il metodo PreferenceManager.getDefaultSharedPreferences()
nella mia applicazione per ottenere l'istanza preferenze predefinite condivisa. Ora ho bisogno di fornire il nome del file. Come faccio a sapere che nome che è?
(E perché non fornisce un aiutante che appena fa un backup DefaultSharedPreferences
?)
Soluzione
Sembra che si chiama "packagename_preferences"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow