vendredi 26 août 2016

Android: what is the best way to send presence?

I want to send that the user is currently using the app to my server in regular interval.

User is active,

  • When he is on any activity of my app and the user should see it in screen.

User is Inactive,

  • If the user is not in any of my app's activity
  • If the user has minimized the app
  • If the user is in my app's activity only, but screen is locked

For this, I have implemented Android's ActivityLifecycleCallbacks and trying to send user is active in onActivityResumed() and inactive in onActivityPaused()

It works as expected, but there are many activities in my app, so transition between Activities also send this presence status, which is very bad for end user.

How can I control this ? How can I send only at regular intervals instead of flooding the presence ?

Generally what is the best way to do something at regular intervals in Android ? which means, the task should be done only on particular intervals even it has called any number of times.

Aucun commentaire:

Enregistrer un commentaire