Android equivalent of NSUserDefaults in iOS

This is the most simple solution I’ve found:

//--Init
int myvar = 12;


//--SAVE Data
SharedPreferences preferences = context.getSharedPreferences("MyPreferences", Context.MODE_PRIVATE);  
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("var1", myvar);
editor.commit();


//--READ data       
myvar = preferences.getInt("var1", 0);  

Where ‘context’ is the current context (e.g. in an activity subclass could be this).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)