@Implements(value=android.os.Looper.class, isInAndroidSdk=false) public class ShadowLegacyLooper extends ShadowLooper
The shadow Looper implementation for LooperMode.Mode.LEGACY.
Robolectric enqueues posted Runnables to be run (on this thread) later. Runnables that are scheduled to run immediately can be triggered by calling idle().
ShadowMessageQueueShadowLooper.Picker| Constructor and Description |
|---|
ShadowLegacyLooper() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
__constructor__(boolean quitAllowed) |
Duration |
getLastScheduledTaskTime() |
static Looper |
getLooperForThread(Thread thread) |
protected static Looper |
getMainLooper() |
Duration |
getNextScheduledTaskTime() |
Scheduler |
getScheduler()
Returns the
Scheduler that is being used to manage the enqueued tasks. |
boolean |
hasQuit() |
void |
idle()
Executes all posted tasks scheduled before or at the current time.
|
void |
idle(long intervalMillis)
Deprecated.
Use
idle(long, TimeUnit). |
void |
idle(long amount,
TimeUnit unit)
Causes
Runnables that have been scheduled to run within the next specified amount of time to run while advancing the clock. |
void |
idleConstantly(boolean shouldIdleConstantly) |
void |
idleFor(long time,
TimeUnit timeUnit)
Advances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.
|
void |
idleIfPaused()
Helper method to selectively call idle() only if LooperMode is PAUSED.
|
boolean |
isIdle()
Returns true if the looper has any pending tasks scheduled to be executed before current time.
|
boolean |
isPaused() |
protected static void |
loop() |
protected static Looper |
myLooper() |
void |
pause()
Pause the looper.
|
boolean |
post(Runnable runnable,
long delayMillis)
Deprecated.
Use a
Handler instance to post to a looper. |
boolean |
postAtFrontOfQueue(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()
Only supported for
LooperMode.Mode.PAUSED. |
static void |
resetThreadLoopers() |
void |
runOneTask()
Causes only one of the next
Runnables that have been scheduled to run while advancing the clock to its start time. |
void |
runPaused(Runnable r)
Runs the current task with the looper paused.
|
void |
runToEndOfTasks()
|
void |
runToNextTask()
Causes the next
Runnable(s) that have been scheduled to run while advancing the clock to its start time. |
boolean |
setPaused(boolean shouldPause)
Control the paused state of the Looper.
|
void |
unPause()
Not supported for the main Looper in
LooperMode.Mode.PAUSED. |
assertLooperMode, getShadowMainLooper, idleFor, idleMainLooper, idleMainLooper, idleMainLooper, idleMainLooperConstantly, looperMode, pauseLooper, pauseMainLooper, runMainLooperOneTask, runMainLooperToNextTask, runUiThreadTasks, runUiThreadTasksIncludingDelayedTasks, shadowMainLooper, unPauseLooper, unPauseMainLooper@Resetter public static void resetThreadLoopers()
@Implementation protected void __constructor__(boolean quitAllowed)
@Implementation protected static Looper getMainLooper()
@Implementation protected static Looper myLooper()
@Implementation protected static void loop()
@Implementation protected void quit()
@Implementation(minSdk=18) protected void quitSafely()
public void quitUnchecked()
quitUnchecked in class ShadowLooperpublic boolean hasQuit()
hasQuit in class ShadowLooperpublic void idle()
ShadowLooperExecutes all posted tasks scheduled before or at the current time.
idle in class ShadowLooperpublic void idleFor(long time,
TimeUnit timeUnit)
ShadowLooperAdvances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.
idleFor in class ShadowLooperpublic boolean isIdle()
ShadowLooperReturns true if the looper has any pending tasks scheduled to be executed before current time.
isIdle in class ShadowLooperpublic void idleIfPaused()
ShadowLooperHelper method to selectively call idle() only if LooperMode is PAUSED.
Intended for backwards compatibility, to avoid changing behavior for tests still using LEGACY LooperMode.
idleIfPaused in class ShadowLooper@Deprecated public void idle(long intervalMillis)
idle(long, TimeUnit).Causes Runnables that have been scheduled to run within the next intervalMillis milliseconds to run while advancing the scheduler’s clock.
idle in class ShadowLooperpublic void idle(long amount,
TimeUnit unit)
ShadowLooperCauses Runnables that have been scheduled to run within the next specified amount of time to run while advancing the clock.
idle in class ShadowLooperpublic void idleConstantly(boolean shouldIdleConstantly)
idleConstantly in class ShadowLooperpublic void runToEndOfTasks()
ShadowLooperCauses all of the Runnables that have been scheduled to run while advancing the clock to the start time of the last scheduled Runnable.
runToEndOfTasks in class ShadowLooperpublic void runToNextTask()
ShadowLooperCauses the next Runnable(s) that have been scheduled to run while advancing the clock to its start time. If more than one Runnable is scheduled to run at this time then they will all be run.
runToNextTask in class ShadowLooperpublic void runOneTask()
ShadowLooperCauses only one of the next Runnables that have been scheduled to run while advancing the clock to its start time. Only one Runnable will run even if more than one has been scheduled to run at the same time.
runOneTask in class ShadowLooper@Deprecated public boolean post(Runnable runnable, long delayMillis)
Handler instance to post to a looper.Enqueue a task to be run later.
post in class ShadowLooperrunnable - the task to be rundelayMillis - how many milliseconds into the (virtual) future to run itHandler.postDelayed(Runnable,long)@Deprecated public boolean postAtFrontOfQueue(Runnable runnable)
Handler instance to post to a looper.Enqueue a task to be run ahead of all other delayed tasks.
postAtFrontOfQueue in class ShadowLooperrunnable - the task to be runHandler.postAtFrontOfQueue(Runnable)public void pause()
ShadowLooperPause the looper.
Has no practical effect for realistic looper, since it is always paused.
pause in class ShadowLooperpublic Duration getNextScheduledTaskTime()
getNextScheduledTaskTime in class ShadowLooperpublic Duration getLastScheduledTaskTime()
getLastScheduledTaskTime in class ShadowLooperpublic void unPause()
ShadowLooperNot supported for the main Looper in LooperMode.Mode.PAUSED.
unPause in class ShadowLooperpublic boolean isPaused()
isPaused in class ShadowLooperpublic boolean setPaused(boolean shouldPause)
ShadowLooperControl the paused state of the Looper.
Not supported for the main Looper in LooperMode.Mode.PAUSED.
setPaused in class ShadowLooperpublic void resetScheduler()
ShadowLooperOnly supported for LooperMode.Mode.PAUSED.
resetScheduler in class ShadowLooperpublic void reset()
Causes all enqueued tasks to be discarded, and pause state to be reset
reset in class ShadowLooperpublic Scheduler getScheduler()
Returns the Scheduler that is being used to manage the enqueued tasks. This scheduler is managed by the Looper’s associated queue.
getScheduler in class ShadowLooperScheduler that is being used to manage the enqueued tasks.public void runPaused(Runnable r)
ShadowLooperRuns the current task with the looper paused.
When LooperMode is PAUSED, this will execute all pending tasks scheduled before the current time.
runPaused in class ShadowLooper