How to stop a thread from starting using postDelayed

I have a service that starts a thread in 15 seconds. This is a piece of code:

        Handler mHandler = new Handler();
        OverclockThread ocThread = new OverclockThread();
        ocThread.ocPreference = readPreference("oc");
        ocThread.serviceOn = true;

        if (Intent.ACTION_SCREEN_ON.equals(action)) {
            ocThread.screenOff = false;
            mHandler.postDelayed(ocThread, 15000);
        }

Now I would like to add the ability to stop the start of my ocThread until these 15 seconds ... for example, by clicking a button or a check box ... which command should I use to stop the thread started using postDelayed?

thank

Simone

+3
source share
1 answer

I used:

mHandler.removeCallbacks(ocThread);
+11
source

Source: https://habr.com/ru/post/1786344/


All Articles