Am trying to store the values in my ArrayList
with SharedPreferences
and access them in another class.This is what i have tried so far.
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();
}
}
Any help would be appreciated.