How to pause / sleep thread or process in Android?

后端 未结 12 985
故里飘歌
故里飘歌 2020-11-22 05:49

I want to make a pause between two lines of code, Let me explain a bit:

-> the user clicks a button (a card in fact) and I show it by changing the background of thi

12条回答
  •  野性不改
    2020-11-22 06:48

    You probably don't want to do it that way. By putting an explicit sleep() in your button-clicked event handler, you would actually lock up the whole UI for a second. One alternative is to use some sort of single-shot Timer. Create a TimerTask to change the background color back to the default color, and schedule it on the Timer.

    Another possibility is to use a Handler. There's a tutorial about somebody who switched from using a Timer to using a Handler.

    Incidentally, you can't pause a process. A Java (or Android) process has at least 1 thread, and you can only sleep threads.

提交回复
热议问题