1

I'm working on my first Android Project, which is a simple card game. Everything works fine so far but now I have some issues with starting/cancelling an activity. I've also read this post, but couldn't find a solution for my problem.

The situation: While I'm connected with the firebase server two players can join a room and play the game. But when one is leaving the issue occurs.

What should happen: One player pushes the button to leave the room, this activates an ValueEventHandler and both players initiate the cancel process (go back to the lobby) and get back to the lobby.

What happens: The button is pushed and the ValueEventHandler starts the process for both players. This is the code of the cancel button:

cancel = true  //simple boolean 
messageRef!!.removeEventListener(listener1!!) //cancel Firebase-Value-Event-Listeners 
(remove all listeners...) 
roomRef!!.setValue(null) //delete room at firebase-server 
val intent = intent(this@gameActivity, LobbyActivity::class.java) //also tried this with applicationContext 
startActivity(intent)

This code is executed. But then this notice occurs:

Cancel Acitivity - handleWindowVisibility: no activity for token android.os.BinderProxy@36ada28 JNI critical lock held (...)

Then the gameActivity is starting again.

Workaround: Push the cancel button after the gameactivity reloaded brings the player back to the lobby (don't know why it works on the second attempt). Anyways - the console shows the same "handleWindowVisibility: no activity for token" error.

Hope for insight & help on this.

c_ph_r
  • 207
  • 3
  • 13

1 Answers1

0

If someone has the same issue : I reworked the code and now it is gone. IMHO it had to do with calling "finish()" twice (at OnStop and at OnDestroy) or maybe even calling the startActivity(intent) twice.

c_ph_r
  • 207
  • 3
  • 13