public class ThreadHandler extends java.lang.Object implements P_SweetHandler
Runnable
s. You shouldn't ever need to subclass this, as it's all implemented for you.
However, if you want SweetBlue to run it's update logic on an already created Thread
in your app (rather than creating a new Thread),
then you will need to use this class. You must make sure to call loop()
within the existing Thread's runnable, otherwise
the class won't execute it's commands.Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.atomic.AtomicBoolean |
m_running |
Constructor and Description |
---|
ThreadHandler()
Create a new instance of ThreadHandler.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Thread |
getThread() |
void |
loop()
If you are running SweetBlue's update logic in your own thread, you must remember to call this method inside of the Runnable
for the your Thread.
|
void |
post(java.lang.Runnable action)
Post a
Runnable to be executed by the Thread backing this handler. |
void |
postDelayed(java.lang.Runnable action,
long delay)
Post a
Runnable to be executed by the Thread backing this handler, delayed by the amount given. |
void |
postDelayed(java.lang.Runnable action,
long delay,
java.lang.Object tag)
Post a
Runnable to be executed by the Thread backing this handler, delayed by the amount given, with the given tag to identify this
action. |
void |
quit() |
void |
removeCallbacks(java.lang.Object tag) |
void |
removeCallbacks(java.lang.Runnable action)
Remove a
Runnable from the handler. |
public ThreadHandler()
loop()
in it's Runnable. This is setup as an update loop, so if your
Thread's runnable doesn't loop, this class won't help much.public final void loop()
public final void post(java.lang.Runnable action)
Runnable
to be executed by the Thread
backing this handler.post
in interface P_SweetHandler
public final void postDelayed(java.lang.Runnable action, long delay)
Runnable
to be executed by the Thread
backing this handler, delayed by the amount given.postDelayed
in interface P_SweetHandler
public void postDelayed(java.lang.Runnable action, long delay, java.lang.Object tag)
Runnable
to be executed by the Thread
backing this handler, delayed by the amount given, with the given tag to identify this
action.postDelayed
in interface P_SweetHandler
removeCallbacks(Object)
public final void removeCallbacks(java.lang.Runnable action)
Runnable
from the handler. If the runnable is currently executing, it will not be canceled.removeCallbacks
in interface P_SweetHandler
public void removeCallbacks(java.lang.Object tag)
removeCallbacks
in interface P_SweetHandler
public void quit()
quit
in interface P_SweetHandler
public java.lang.Thread getThread()
getThread
in interface P_SweetHandler