I use Firestore to save the account status, when the account is active the value of the status field is changed to online and when he logs out of the account the status changes to offline. By sending an order to change the status.
But there are two problems!
First: When the account loses the internet connection, how to change the status to Offline?
Second: When the user close the application through the display button of the active applications on the device
How to solve these problems, note that I searched for a long time and did not find a logical solution.