My app is picking up the same settings even after using Finish

Asked

Viewed 33 times

0

I’m a beginner on android and I’m developing a chat app in which I connect two people based on their preferences. When one of the two people ends the conversation and decides to go back to the queue by choosing the same option as before (example: help), it ends up being redirected to the same user as before. In my code I used Finish to finalize the chat screen when she chose to leave the conversation, but I don’t know exactly where I’m going wrong. Is there anything I can do before giving Finish that prevents my app from picking up the settings of the user he talked to when joining the queue again?

Class used:

Queuing(Here the user is waiting for someone): Pastebin

I tried to reload Activity before queuing up again using Recreation and opening a new Input for the same page. But my app hangs with it. I don’t know what to do. Thank you very much to anyone who can give me a light!

1 answer

1

I’ve solved the problem! I had created an eventListener to search for other users to talk to and when I found one I opened a new chat screen without closing this eventlistener. So even if I ended the conversation, there was already an old open eventlistener who would always redirect me to the same user as before if he clicked in the queue again.

Basically to solve the problem I needed to remove the eventlistener within the onStop method. I’ll leave the method here!

@Override
protected void onStop() {
    super.onStop();

    if (this.isFinishing() || this.isDestroyed()){
        /*Se a activity foi fechada então remove o eventlistener*/

        if (this.opcao == 1){
            filaFirebaseTeAjudo.removeEventListener(valueMeAjudateAjudo);

        } else if (this.opcao == 2){
            filaFirebaseMeAjuda.removeEventListener(valueTeAjudoMeAjuda);

        } else {
            filaFirebaseAmbos.removeEventListener(ambos);
        }

        Toast.makeText(getApplicationContext(),
                "onStop-saiu", Toast.LENGTH_SHORT).show();
    }
}

Browser other questions tagged

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