0

I have to add the following feature in my android application.

There is a client, when the client logs into the application, clicks a button to make themselves available to the user by going online. When he clicks the button a rest call is made, and which change the DB status(status changed to online) and make him online.

Now my problem is I want to make the client unavailable(offline) if the app is getting forced close or removed by android from the background due to low memory or removed by the user from the recent app. If any of these situations occur I do a rest call to handle the situation.

In the normal scenario if he is online he can simply click the button again to make a rest call which will change his status to unavailable(offline) in DB.

NOTE: I don't want to use onPause() or onStop() method because I want the client to be online even if he navigates out of the application and comes back.

Vega
  • 27,856
  • 27
  • 95
  • 103
Shreyash
  • 81
  • 1
  • 1
  • 5

1 Answers1

0

In principle you can't because there's always a case when user can get disconnected without feedback (e.g. losing signal, battery).

IMO you should look for ways to detect the timeout from the server side, similar to socket.io disconnect() outlined in this SO answer.

Laur Ivan
  • 4,117
  • 3
  • 38
  • 62
  • This will be on the server side. That's good I can try this. But anything from the application side, something like broadcast receiver ?? – Shreyash Sep 16 '17 at 16:01
  • you can follow [this answer](https://stackoverflow.com/a/19560863/515948) to catch some events (e.g. `onStop` or `onDestroy`), but there are always situations when such events are not emitted. – Laur Ivan Sep 17 '17 at 17:15