I am trying to create an android application in which I want to clear all my saved data from Shared preference when my phone's date changed.Each day when I opened my app first time my Shared preference should be null.How can i achieve that.
Asked
Active
Viewed 664 times
1
-
3you can manage this by saving current date in SharedPreference an while your app is load first activity you can check the current date is greater previous date than you can perform operation for clear preference – Abhishek Patel May 30 '16 at 06:57
2 Answers
0
->Create alarm manager for when you need to delete your sharedPreference
->So alarm manager will trigger on particular time which you defined and register a custom broadcast receiver while alarm manager tigger.for example look in to this link (Android Alarm Manager with broadcast receiver registered in code rather than manifest)
->clear your saved data in on receive method of broadcast receiver.
Community
- 1
- 1
ArunPrasathYuva
- 16
- 1
0
Save the today date in today_date in shared pref or db as per ur requirment. and on every start just check it with current date. ur logic will be some what like
if(today_date != current_date)
{
erase sharef pref or db
}
Shahensha Khan
- 265
- 1
- 19