I have an ArrayList
with custom objects. Each custom object contains a variety of strings and numbers. I need the array to stick around even if the user leaves
public void saveUserName(Context con,String username)
{
try
{
usernameSharedPreferences= PreferenceManager.getDefaultSharedPreferences(con);
usernameEditor = usernameSharedPreferences.edit();
usernameEditor.putInt(PREFS_KEY_SIZE,(USERNAME.size()+1));
int size=USERNAME.size();//USERNAME is arrayList
usernameEditor.putString(PREFS_KEY_USERNAME+size,username);
usernameEditor.commit();
}
catch(Exception e)
{
e.printStackTrace();
}
}
public void loadUserName(Context con)
{
try
{
usernameSharedPreferences= PreferenceManager.getDefaultSharedPreferences(con);
size=usernameSharedPreferences.getInt(PREFS_KEY_SIZE,size);
USERNAME.clear();
for(int i=0;i(this, android.R.layout.simple_dropdown_item_1line, USERNAME);
username.setAdapter(usernameArrayAdapter);
username.setThreshold(0);
}
catch(Exception e)
{
e.printStackTrace();
}
}