I'm building an android app where the server needs to know if the user is still online or not.
You can compare it with facebook chat on android. If the user is on the app, other users can see he is online. But when the user loses internet connection or closes the app the server needs to know he is not online anymore.
What is the best way to do this?
It depends on your server type. For example if you use
sip you can do this by sending registration message before expire time.
But in general the common practice is to send a
keep_alive message within a short interval. if you use any third party standard server then read their documentation and apply that way. If you are planning to create your own server system then just create a custom
keep_alive message format and send it to server at regular interval.