tntv
tntv

Reputation: 118

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

Upvotes: 0

Views: 682

Answers (2)

Matt Colliss
Matt Colliss

Reputation: 1414

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.

Upvotes: 2

Heiko Rupp
Heiko Rupp

Reputation: 30934

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.

Upvotes: 3

Related Questions