Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android read/write user preferences

I am migrating iOS app to android and, thinking about iOS, I set a default plist file with strings and keys that are then modified using NSuserDefaults. I read some posts and docs and not really clear about how to do it properly in Android. I need a preferences file with keys and strings that I could read and write. Thank you.

like image 685
Jaume Avatar asked May 26 '26 14:05

Jaume


1 Answers

SharedPreferences settings;
settings = getSharedPreferences("PREF_NAME", Context.MODE_PRIVATE);

//get the sharepref
int id = settings.getInt("ID", 0);

//set the sharedpref
Editor editor = settings.edit();
editor.putInt("ID", "1");
editor.commit();
like image 180
Bhavesh Vadalia Avatar answered May 30 '26 05:05

Bhavesh Vadalia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!