0

I am building a android app and I would like to store a 4 digit number (pin), without setting up any database.

That 4 digit number would be password for the app.

I know how to set up the SQLite database but it seems to much work for just 4 digit number

Cheesebaron
  • 21,926
  • 13
  • 60
  • 110
KillGeek
  • 83
  • 1
  • 9
  • 3
    Possible duplicate of [Android Shared preferences example](http://stackoverflow.com/questions/23024831/android-shared-preferences-example) – SripadRaj Oct 15 '16 at 09:16

3 Answers3

1

Android SharedPreferences will do the job:

var prefs = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
var editor = prefs.Edit();
editor.PutString("MyFourDigitString", "1234");
editor.Apply();

var MyFourDigitString = prefs.GetString("MyFourDigitString", "0000"); // 0000 = default value
SushiHangover
  • 68,368
  • 9
  • 89
  • 150
0

To save information you have following options:

  1. SQLite Database
  2. Shared Preference
  3. File System

If you don't want to use the SQLite Database, then go for Shared Preference. But when user remove data from settings, then it will remove.

Please read the following URL for more details.

https://developer.android.com/training/basics/data-storage/index.html

https://developer.android.com/guide/topics/data/data-storage.html

Cheers!!!

Amit Goyal
  • 61
  • 2
0

Use Shared Preferences. As you are storing password in preferences, so it must be stored as encrypted data. Example is here

Community
  • 1
  • 1
Arbaz Alam
  • 1,036
  • 13
  • 23