3

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

Simone
  • 795
  • 2
  • 7
  • 17
  • possible duplicate of [How to remove a runnable from a handler object added by postDelayed?](http://stackoverflow.com/questions/3627216/how-to-remove-a-runnable-from-a-handler-object-added-by-postdelayed) – sschuberth Jul 05 '13 at 14:15

1 Answers1

11

I'have used:

mHandler.removeCallbacks(ocThread);
Aziz Shaikh
  • 16,245
  • 11
  • 62
  • 79
Simone
  • 795
  • 2
  • 7
  • 17