我试图将ArrayList
中的值存储到SharedPreferences
并在另一个类中访问它们。这是我到目前为止所尝试过的。
public class sample {
final static String file = "myFile";
SharedPreferences fileName;
protected void onCreate(Bundle savedInstanceState) {
Sharedpreferences.Editor list = SharedPreferences.edit();
list.putStringArray("key", 0);
list.commit();
}
}
public class sample2 {
String array[] = {"can", "you", "help", "me", "with", "this?"};
protected void onCreate(Bundle savedInstanceState) {
Random random = new Random();
int x;
x = random.nextInt(5);
String generatedValue = arr[x];
String get = fileName.getString("key", 0);
SharedPreference.Editor editList = SharedPreferences.edit();
editList.putString("key", get);
editList.commit();
}
}
任何帮助都将不胜感激。