Update variable on new month without fail
I开发者_开发百科 have a variable that needs to be updated the first time my app is started after a new month has begun. It needs to be reliable. Any idea on the simplest way to handle this?
Roger, I would just use a SharedPreference
to store the month that the app was last launched and check it in the onCreate()
method of your main Activity
.
just perform the following in your onCreate()
- Get value of
SharedPreference
(check if its never been initialized = first launch ever) - Get current month value
- If they aren't equal, the month has changed
- store new month value in
SharedPreference
- do whatever you wanted based on a new month starting
精彩评论