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.
Asked
Active
Viewed 882 times
0
-
1can't you add this info in the SharedPreference as well? – Blackbelt Jul 13 '16 at 09:48
-
@Blackbelt, I can add it. But I wanted to know is there any way to get last modified date time for shared preferences value. – Prabhu M Jul 13 '16 at 09:53
-
you can get the last time the file was accessed, but no one can give you the assurance that it was accessed to write a particular information – Blackbelt Jul 13 '16 at 09:58
-
1No. That is not possible. You must save the date/time yourself. – Budius Jul 13 '16 at 11:07
3 Answers
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

Andrea Montanari
- 88
- 1
- 9