Thread.Sleep() Android UI

后端 未结 2 1970
旧时难觅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.

    0 讨论(0)
  • 2020-12-21 13:35

    This is similar to Waiting in android app

    Try following the solution posted there and use the Timer Class

    0 讨论(0)
提交回复
热议问题