How can I fix this intent issue?

2019-09-09 08:53发布

TL;DR:

How can I give one intent a preference over another?

If two intents are run at the same time, I want only one of those intents to start.


My game has a 20 second timer running in the background service, and when that timer ends, a new activity (game over screen) starts through an intent. The user is pressing buttons to change activities (again, through intent) in those 20 seconds.

The problem is, if the user pushes a button at the same time that the timer ends, the next activity starts rather than the game over screen. Now, the timer is over, and the user is stuck randomly pushing buttons for no reason. How can I fix this? Is there any way to make sure that the Game Over screen will open up after 20 seconds?

I haven't provided much code, because it is mainly just starting intents. If you need any detail, feel free to ask me.

2条回答
迷人小祖宗
2楼-- · 2019-09-09 09:21

I am suggesting you to take a global variable as a flag, let say int = 0 Now initialize it as "0" and on your both intents give condition as below:

 if(i == "0"){
    .
    .
    .
    //fire your intent..
i= 1;
    }

,And then flush that variable to "0" whenever you want.Hope you got idea.

查看更多
叼着烟拽天下
3楼-- · 2019-09-09 09:36

do timer checking on user click event should do it. or you can use flag/boolean to maintain state.

i dont know your code, just use simple conditional if..

 if (timer <= 0){
      //open whatever u want and reset timer again..
 }
查看更多
登录 后发表回答