One of my company's app's requirements is a tracking system, where a user can track other nearby users when using our app. So there is a map and user's location (coordinates) will be updating to Firebase so other users can see on their map.
The most important thing is that we don't want sign out/offline users' location data on Firebase (because we want users only to be able to see online nearby users) so I use Firebase's onDisconnectRemoveValue()
method to automatically remove disconnected users' data. The method worked great. BUT, if the app goes to the background (or screen is turned off), onDisconnectRemoveValue
is fired too, so the data will be deleted (I don't want it to be deleted).
I searched the Internet, found this SO post.
This method is designed that way, I think I cannot do anything about it.
So my question is: If I want to remove a data on Firebase if the user is disconnected (loss internet connection OR app closed/killed), how can I do that?
Additional info: because I want users can updating their location to Firebase even if the App go to the background or device screen is off so I cannot check the connection at the client (can check, but when connection loss detected, cannot send remove data request to Firebase).