Ahmad Sabbagh
Ahmad Sabbagh

Reputation: 27

How can i know if the user is using my android application "now"

I need to know if the user is using my application at the moment. My idea is to make a method to make his status on in the first activity.

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_admin_page);
    makemeonline();
}

But how can I know if the user didn't just close the application or move it to the background?

Upvotes: 1

Views: 74

Answers (1)

Reaz Murshed
Reaz Murshed

Reputation: 24211

You can override the onPause function. In your onPause function, do something like this.

@Override
public void onPause() {
    super.onPause();
    makeUserIdle();
}

You can not really detect if the user is not connected to internet as I suppose makeMeOnline is calling an API to get the user status posted to some server. If you want the user to track user offline as well, then you might just consider saving the values in your sqlite database and then upload the behaviour data later to the server through another API call when the device is connected to internet.

If you integrate google analytics with your project, you can have an estimate of how many users are currently using your application in the play developer console as well.

Upvotes: 1

Related Questions