1
Good night! I’m a beginner on android and I’m developing a chat app where two users connect through a queue based on their chosen preferences. When one of the users disconnects from the chat (end Activity) I want to save the status in firebase to inform the other user that the person with whom he was talking came out conversation.
How can I check whether my Activity has been destroyed or not? I tested using a boleana variable with active name and set it as trrue in onStart and false in onDestroy. I have also tried using the isDestroyed method to see if Activity has been terminated. But I am failing at this.
I don’t know where I do this check to test the value of these boolean variables. I tried to check onStart but it didn’t work. What should I do? Below are the methods I’ve done.
public boolean appAberto(){
//Se foi destruido retorna false, se esta aberto retorna true
if (ChatPrivadoActivity.this.isDestroyed()){
//retorna true se foi destruido
//isFinishing Verifica se a activity esta em procersso de finalização
Toast.makeText(this,
"ENCERROU", Toast.LENGTH_SHORT).show();
return false;
}
return true;
}
I called this function on onStart and did not return anything even after I closed Activity. Then I tried this:
@Override
protected void onStart() {
super.onStart();
recuperarMensagensConversa();
ativo = true;
}
@Override
protected void onStop() {
super.onStop();
ativo = false;
}
@Override
protected void onDestroy() {
super.onDestroy();
ativo = false;
}
But I didn’t succeed because I didn’t know exactly where to test this variable I created. What I’m doing wrong?
Puts this variable Boolean only in onResume and onPause, onResume true and onPause false, I believe it works
– Murillo Comino