Reputation: 1563
I have an android application where want to update my remote database when the application is killed. Now I use onTaskRemoved() method of one of my Service where I handle when the application is removed from the current applications list and send Intent to BroadcastReceiver where call a request to my remote database (want to wait the response from the back-end if the write operation is success). This approach not works all the time.
The main idea is to know which users are in their applications and which killed it.
Upvotes: 1
Views: 402
Reputation: 7
Firebase hasn't provided support for such thing. So you need to work something out. Firebase updates data only when the app is in background not when it is killed.
Or try this this might help
Keep app running in background on Android all the time
Upvotes: 0
Reputation: 7922
You can use onDisconnect()
to update the database when a device is no longer connected. Usage would look like:
databaseReference.onDisconnect().setValue(true);
You set this while your app is running, the remote database doesn't immediately write it, but when your app disconnects, then Firebase will update that value to the database.
More about onDisconnect()
as well as an example for showing when a user goes offline are found in the documentation here.
Upvotes: 1