I just managed to delete my last question by accident so here it is again.
I have the below class which I chucked together to test the preferences class. The problem I am facing is that when I pass or call from the preferences class nothing happens. The code compiles fine but I'm unable to get or set my preferences. It appears to be getting stuck on SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
as I have used some print statements to see where it stops. I have tried the using the example on the android site but that does not help. Anyone got any ideas?
public class Preferences extends Activity{
public void getSetPrefs(){
Preferences p = new Preferences();
p.setLocationPref("london", "1");
String location = p.getLocation();
String location_id = p.getLocation();
}
}
//Preferences class
public class Preferences extends Activity{
/** Sets location preferences */
public void setLocationPref(String location, int location_id){
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("location", location);
editor.putInt("location_id", location_id);
editor.commit();
}
/** Get location from preferences */
public String getLocation(){
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
String location = sharedPreferences.getString("location", "");
return location;
}
/** Get location ID from preferences */
public int getLocationID(){
SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);
int locationID = sharedPreferences.getInt("location_id", 0);
return locationID;
}
}