@Implements(value=android.os.Looper.class) public class ShadowLooper extends java.lang.Object
Robolectric enqueues posted Runnable
s to be run (on this thread) later. Runnable
s that are scheduled to run immediately can be triggered by calling idle()
.
ShadowMessageQueue
Constructor and Description |
---|
ShadowLooper() |
Modifier and Type | Method and Description |
---|---|
protected void |
__constructor__(boolean quitAllowed) |
static android.os.Looper |
getLooperForThread(java.lang.Thread thread) |
protected static android.os.Looper |
getMainLooper() |
Scheduler |
getScheduler()
Returns the
Scheduler that is being used to manage the enqueued tasks. |
static ShadowLooper |
getShadowMainLooper()
Deprecated.
Use
shadowOf( instead. |
boolean |
hasQuit() |
void |
idle()
Causes
Runnable s that have been scheduled to run immediately to actually run. |
void |
idle(long intervalMillis)
Deprecated.
Use
idle(long, TimeUnit) . |
void |
idle(long amount,
java.util.concurrent.TimeUnit unit)
Causes
Runnable s that have been scheduled to run within the next specified amount of time to run while advancing the scheduler’s clock. |
void |
idleConstantly(boolean shouldIdleConstantly) |
static void |
idleMainLooper() |
static void |
idleMainLooper(long interval)
Deprecated.
|
static void |
idleMainLooper(long amount,
java.util.concurrent.TimeUnit unit) |
static void |
idleMainLooperConstantly(boolean shouldIdleConstantly) |
boolean |
isPaused() |
protected static void |
loop() |
protected static android.os.Looper |
myLooper() |
void |
pause() |
static void |
pauseLooper(android.os.Looper looper) |
static void |
pauseMainLooper() |
boolean |
post(java.lang.Runnable runnable,
long delayMillis)
Deprecated.
Use a
Handler instance to post to a looper. |
boolean |
postAtFrontOfQueue(java.lang.Runnable runnable)
Deprecated.
Use a
Handler instance to post to a looper. |
protected void |
quit() |
protected void |
quitSafely() |
void |
quitUnchecked() |
void |
reset()
Causes all enqueued tasks to be discarded, and pause state to be reset
|
void |
resetScheduler() |
static void |
resetThreadLoopers() |
static void |
runMainLooperOneTask() |
static void |
runMainLooperToNextTask() |
void |
runOneTask()
Causes only one of the next
Runnable s that have been scheduled to run while advancing the scheduler’s clock to its start time. |
void |
runPaused(java.lang.Runnable r) |
void |
runToEndOfTasks()
Causes all of the
Runnable s that have been scheduled to run while advancing the scheduler’s clock to the start time of the last scheduled Runnable . |
void |
runToNextTask()
Causes the next
Runnable (s) that have been scheduled to run while advancing the scheduler’s clock to its start time. |
static void |
runUiThreadTasks()
Runs any immediately runnable tasks previously queued on the UI thread, e.g.
|
static void |
runUiThreadTasksIncludingDelayedTasks()
Runs all runnable tasks (pending and future) that have been queued on the UI thread.
|
boolean |
setPaused(boolean shouldPause) |
void |
unPause() |
static void |
unPauseLooper(android.os.Looper looper) |
static void |
unPauseMainLooper() |
@Resetter public static void resetThreadLoopers()
@Implementation protected void __constructor__(boolean quitAllowed)
@Implementation protected static android.os.Looper getMainLooper()
@Implementation protected static android.os.Looper myLooper()
@Implementation protected static void loop()
@Implementation protected void quit()
@Implementation(minSdk=18) protected void quitSafely()
public void quitUnchecked()
public boolean hasQuit()
@Deprecated public static ShadowLooper getShadowMainLooper()
shadowOf(Looper.getMainLooper()
)
instead.public static android.os.Looper getLooperForThread(java.lang.Thread thread)
public static void pauseLooper(android.os.Looper looper)
public static void unPauseLooper(android.os.Looper looper)
public static void pauseMainLooper()
public static void unPauseMainLooper()
public static void idleMainLooper()
@Deprecated public static void idleMainLooper(long interval)
idleMainLooper(long, TimeUnit)
.public static void idleMainLooper(long amount, java.util.concurrent.TimeUnit unit)
public static void idleMainLooperConstantly(boolean shouldIdleConstantly)
public static void runMainLooperOneTask()
public static void runMainLooperToNextTask()
public static void runUiThreadTasks()
Runs any immediately runnable tasks previously queued on the UI thread, e.g. by Activity.runOnUiThread(Runnable)
or AsyncTask.onPostExecute(Object)
.
Note: calling this method does not pause or un-pause the scheduler.
runUiThreadTasksIncludingDelayedTasks()
public static void runUiThreadTasksIncludingDelayedTasks()
Runs all runnable tasks (pending and future) that have been queued on the UI thread. Such tasks may be queued by e.g. Activity.runOnUiThread(Runnable)
or AsyncTask.onPostExecute(Object)
.
Note: calling this method does not pause or un-pause the scheduler, however the clock is advanced as future tasks are run.
runUiThreadTasks()
public void idle()
Causes Runnable
s that have been scheduled to run immediately to actually run. Does not advance the scheduler’s clock;
@Deprecated public void idle(long intervalMillis)
idle(long, TimeUnit)
.Causes Runnable
s that have been scheduled to run within the next intervalMillis
milliseconds to run while advancing the scheduler’s clock.
public void idle(long amount, java.util.concurrent.TimeUnit unit)
Causes Runnable
s that have been scheduled to run within the next specified amount of time to run while advancing the scheduler’s clock.
public void idleConstantly(boolean shouldIdleConstantly)
public void runToEndOfTasks()
Causes all of the Runnable
s that have been scheduled to run while advancing the scheduler’s clock to the start time of the last scheduled Runnable
.
public void runToNextTask()
Causes the next Runnable
(s) that have been scheduled to run while advancing the scheduler’s clock to its start time. If more than one Runnable
is scheduled to run at this time then they will all be run.
public void runOneTask()
Causes only one of the next Runnable
s that have been scheduled to run while advancing the scheduler’s clock to its start time. Only one Runnable
will run even if more than one has ben scheduled to run at the same time.
@Deprecated public boolean post(java.lang.Runnable runnable, long delayMillis)
Handler
instance to post to a looper.Enqueue a task to be run later.
runnable
- the task to be rundelayMillis
- how many milliseconds into the (virtual) future to run itHandler.postDelayed(Runnable,long)
@Deprecated public boolean postAtFrontOfQueue(java.lang.Runnable runnable)
Handler
instance to post to a looper.Enqueue a task to be run ahead of all other delayed tasks.
runnable
- the task to be runHandler.postAtFrontOfQueue(Runnable)
public void pause()
public void unPause()
public boolean isPaused()
public boolean setPaused(boolean shouldPause)
public void resetScheduler()
public void reset()
Causes all enqueued tasks to be discarded, and pause state to be reset
public Scheduler getScheduler()
Returns the Scheduler
that is being used to manage the enqueued tasks. This scheduler is managed by the Looper’s associated queue.
Scheduler
that is being used to manage the enqueued tasks.public void runPaused(java.lang.Runnable r)