I'm developing one chat application. If the status is "1", I'm showing the user is in Online else if the status is "0" I'm showing the user is in Offline.
I have taken the status API from back end team. Hence my issue is whenever if user uninstall the chat application still it is showing the user is in Online.
How to resolve this issue?
Thanks in advance.
How to update the status of user from online to offline if user uninstall the application in android
Asked
Active
Viewed 116 times
0

Rama Krishna
- 15
- 5
-
1you are unable to trigger anything when your app is uninstalled. What you can do if ping server every xxx seconds. If the user does not ping the server - he is offline. – Vladyslav Matviienko Oct 09 '17 at 07:08
-
https://stackoverflow.com/questions/3013823/perform-a-task-on-uninstall-in-android – Amjad Omari Oct 09 '17 at 07:08
-
@VladMatvienko even offline status also I'm sending to server using `onBackpressed()` or `onDestroy()` methods. – Rama Krishna Oct 09 '17 at 07:57
1 Answers
0
Ok, so the problem here is that whenever user uninstalls your app, Android just kills everything - Processes, Services, everything associated and created with your app. And there's really no way to send the last "good-bye" message within your app.
However you can make you client(app) to send some kind of ping-request to your back-end, so you back-end could check that and if it's not receiving any ping-requests for n-amount of time - client is offline.

Paul Freez
- 1,059
- 15
- 27
-
How can I send request to back-end? Where can I write code for that request? – Rama Krishna Oct 09 '17 at 13:34
-
@RamaKrishna To your server. You may want to create a service which will make such server requests every n amount of time. Such service should be started whenever you send your first "online" request and stopped whenever you wish to send "offline" status (as you wrote - on your in `onBackpressed()` or `onDestroy()` methods – Paul Freez Oct 10 '17 at 05:37