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.
精彩评论