2

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.

ucMedia
  • 3,221
  • 4
  • 32
  • 42
Jaume
  • 3,514
  • 16
  • 53
  • 115

1 Answers1

22
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();
A--C
  • 36,071
  • 10
  • 105
  • 92
Bhavesh Vadalia
  • 369
  • 2
  • 7