0

I am using shared preferences to store userId once user login to the app. I need to expire(delete) the stored userId after 30 days once the userId is stored on shared preferences. Is it possible to get the last modified date and time of specific shared preference value.

Prabhu M
  • 3,534
  • 8
  • 48
  • 87

3 Answers3

0

It's not possible, SharedPreferences don't have any built in method to do this. You'll have to store last modification date manually, possible in SharedPreferences as well.

Marcin Koziński
  • 10,835
  • 3
  • 47
  • 61
0

I would say you can get the path of the SharedPreferences file and try using lastModified() of File class like,

File file = new File("path of shared-preference file");
file.lastModified();
Lalit Poptani
  • 67,150
  • 23
  • 161
  • 242
-2

Actually you could create an Alarm: you can set it to run within 30 days from the "registration" for the value stored in SharedPreferences. You can then use a Receiver (search for more examples) to catch the alarm and run your code. An example here