I have 2 buttons in the program. Pause and Start. How to make it so that it was possible to stop a stream using the pause button. let's say

Thread. And on the Start button, continue the flow.

But so that the main thread is not frozen.

If Thread is not suitable for this operation. What should I use then?

  • 2
    You would describe the task you are trying to solve, and not the way on the threads. For something strange you do with the threads. When starting a new thread, no other threads freeze if they are not forced to start waiting for something from the new thread. - xkor
  • @xkor There is a certain function. This function runs every 10 seconds. Need to interact buttons start and pause. If I hit start. and for the remaining 8 seconds. I pressed a pause. And after an hour, press the Start button again after 2 seconds. This function should start ... - Andro
  • @xTIGRx and tried to make a handler-based function, which will support the remaining time, if you press a pause, then do nothing. - pavel
  • @pavel, nea. I don `t know how. Can't use TimerTask? Well, so that the pause worked? - Andro

1 answer 1

Try this with the help of the background service, there are enough examples on this topic. First look here . Your background will be sent when you need an alert in the main activity (simulated stop) and vice versa! Alternatively, you can try using ScheduledExecutorService, but you need to specify the task repetition interval there.