-1

I am making a lock screen application. In my application, i want to store a PIN.. But every time when my activity called from the service, The PIN value is being resetted. So i want to store the value of PIN in some permanent place. Is there any way to store the PIN to a text file in R.drawable ? or is there any better ways ? Please help me

Abin Thaha
  • 4,493
  • 3
  • 13
  • 41

3 Answers3

0

Yeah you don't want to put it in the resource folder. Use SharedPreferences instead.

TofferJ
  • 4,678
  • 1
  • 37
  • 49
0

To save a value:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
prefs.edit().putString("pin",your_pin).apply();

To read a value:

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String pin = prefs.getString("pin","default pin");
ByteHamster
  • 4,884
  • 9
  • 38
  • 53
  • Thanks. But i tried SharedPreference. But each time my Activity being called from the Service , the value stroing in SharedPreference also changing. It is working like the first time – Abin Thaha Feb 22 '15 at 15:12
0

Is there any way to store the PIN to a text file in R.drawable

No not possible to write or change files in any folder which bundle with apk.

is there any better ways ?

Use following ways to store data in application:

1. Use SharedPreferences for saving data

2. Create file for saving data in internal directory for your app using getFilesDir()

3. Create file for saving data in internal directory for your app's temporary cache files using getCacheDir()

NOTE : all files created using above methods will delete when application un-install or cache is clear from Application Manager.

ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • I tried using SharedPrefences .. but each time when my Activity is called from the service, the values being stored in the object of SharedPreference also changing.. Can you provide some example code – Abin Thaha Feb 22 '15 at 15:09
  • @Abinthaha : if you want to not update values then use `SharedPreferences.contains(key)` for checking if key is exist then no need to add otherwise new value – ρяσѕρєя K Feb 22 '15 at 15:14