How can I fix this intent issue?

好久不见. 提交于 2019-12-13 05:13:24

问题


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.


回答1:


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..
 }



回答2:


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.



来源:https://stackoverflow.com/questions/34238020/how-can-i-fix-this-intent-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!