Find out if App has been terminated

Asked

Viewed 69 times

1

Hi, I’m a beginner in android and I’m developing an app. I can find out if my Activity was closed using the onStop method using isFinishing() and isDestroyed() and that went very well. But I would like to know how to find out if the App was manually closed by the user because when I close my app the onStop method where I put the check is not triggered. The same occurs when my app closes because it suffered some error (Ex: the app stopped working). I need this control because there is a queue in my app and the users who are in the queue I saved in firebase. But if the user closes the app manually or the app closes by error I’m not able to do the treatment to remove it from firebase. What should I do? This is the method I did on onStop, but it only works when Activity is closed.

protected void onStop() {
super.onStop();
if (ChatPrivadoActivity.this.isFinishing() || ChatPrivadoActivity.this.isDestroyed()){           

        Toast.makeText(this,
                "onStop-fechou o app", Toast.LENGTH_SHORT).show();                
        finish();            
}

}

  • 1

    To my knowledge it is not possible to receive information when the application is forced by the user to stop, when the phone needs memory, or when crashes. But to make it easier you can send information when the app is going first and/or second. Maybe this link will give you a light: Processlifecycleowner and this showing an example Example in English

  • Thank you so much, I’ll look at the link! I think in this case I will add a maximum time for the user to stand in the queue, so even if he has manually terminated the application or he has suffered some error the user will be released from the queue.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.