Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop the launch of a thread done with postDelayed

I have a service tha launch a thread after 15 sec. This is a snippet of my 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'd like to add the ability to stop the launching of my ocThread before these 15 seconds...for example by pressing a button or a checkbox...which command I have to use to stop a thread launched with postDelayed?

thanks

simone

like image 356
Simone Avatar asked Nov 27 '25 20:11

Simone


1 Answers

I'have used:

mHandler.removeCallbacks(ocThread);
like image 117
Simone Avatar answered Nov 30 '25 11:11

Simone



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!