Thread.Sleep() Android UI

后端 未结 2 1972
旧时难觅i
旧时难觅i 2020-12-21 12:52

I\'m working on a memory game for Android and I\'m having a problem. When the user taps the second image - if the images are not the same I want the second image to show for

2条回答
  •  天涯浪人
    2020-12-21 13:34

    You must not sleep the UI thread as this would prevent android from delivering any other events to your activity's UI.

    Instead, do something such as use a timer and have the timer's method use the run on ui thread facility to make the desired postponed change.

    For robustness you may need to implement a state machine (either formally, or in effect) to keep track of what is supposed to be happening - you'll need to decide if the current delay should be aborted or enforced if another button is pushed, and make the state machine treat that appropriately.

提交回复
热议问题