开发者

Update variable on new month without fail

开发者 https://www.devze.com 2023-02-25 04:53 出处:网络
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 wo

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()

  1. Get value of SharedPreference (check if its never been initialized = first launch ever)
  2. Get current month value
  3. If they aren't equal, the month has changed
  4. store new month value in SharedPreference
  5. do whatever you wanted based on a new month starting
0

精彩评论

暂无评论...
验证码 换一张
取 消