开发者

Determining how much time has passed since the app was last used in android?

I want to display a msg to the user like "You have been not using this app since 开发者_StackOverflow社区XXX days". How exactly can i do that in android? can we store the time info in shared preferences and then do the comparison with present date. am facing trouble handling time info in shared preferences. Would like to know if there are any other solutions to this prob


Yes, the solution via shared preferences is a doable one. You can store the date as a long and then construct the new date later from this long.


I would suggest having all of your Activity classes update a timestamp stored in shared preferences when their onPause() method is called.

The easiest way to have this functionality across all of the activities in your app would be to have them all extend some base activity and just put the code in the onPause() method of that.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜