Android - Przechowywanie / pobieranie ciągów ze wspólnymi preferencjami
Jak mówi tytuł, chcę zapisać i pobrać pewne ciągi. Ale mój kod nie przejdzie przez pierwszą linię ani w wyszukiwarce, ani w sklepie. Próbowałem śledzić ten link:http://developer.android.com/guide/topics/data/data-storage.html
private void savepath(String pathtilsave, int i) {
String tal = null;
// doesn't go past the line below
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
tal = String.valueOf(i);
editor.putString(tal, pathtilsave);
editor.commit();
}
i moja metoda pobierania:
public void getpaths() {
String tal = null;
// doesn't go past the line below
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
for (int i = 1; i <= lydliste.length - 1; i++) {
tal = String.valueOf(i);
String restoredText = settings.getString(tal, null);
if (restoredText != null) {
lydliste[i] = restoredText;
}
}
}
lydliste jest statyczną tablicą ciągów.PREFS_NAME
jest
public static final String PREFS_NAME = "MyPrefsFile";