Class ShadowLegacyLooper
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().
- See Also:
- 
Nested Class SummaryNested classes/interfaces inherited from class org.robolectric.shadows.ShadowLooperShadowLooper.Picker
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionprotected void__constructor__(boolean quitAllowed) static LoopergetLooperForThread(Thread thread) protected static Collection<Looper> Return loopers for all threads including main thread.protected static LooperReturns the scheduled time of the next posted task; Duration.ZERO if there is no currently scheduled task.Returns theSchedulerthat is being used to manage the enqueued tasks.booleanhasQuit()voididle()Executes all posted tasks scheduled before or at the current time.voididleConstantly(boolean shouldIdleConstantly) voidAdvances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.voidHelper method to selectively call idle() only if LooperMode is PAUSED.static voidInternal API to initialize background thread scheduler from AndroidTestEnvironment.booleanisIdle()Returns true if there are no pending tasks scheduled to be executed before current time.booleanisPaused()protected static voidloop()protected static LoopermyLooper()voidpause()Pause the looper.booleanDeprecated.booleanpostAtFrontOfQueue(Runnable runnable) Deprecated.Use aHandlerinstance to post to a looper.protected voidquit()protected voidvoidvoidreset()Causes all enqueued tasks to be discarded, and pause state to be resetvoidOnly supported forLooperMode.Mode.LEGACY.static voidvoidCauses only one of the nextRunnables that have been scheduled to run while advancing the clock to its start time.voidRuns the current task with the looper paused.voidvoidCauses the nextRunnable(s) that have been scheduled to run while advancing the clock to its start time.voidContinuously run all Messages on this Looper until its queue is empty.booleansetPaused(boolean shouldPause) Control the paused state of the Looper.voidunPause()Not supported for the main Looper inLooperMode.Mode.PAUSED.Methods inherited from class org.robolectric.shadows.ShadowLooperassertLooperMode, clearLooperMode, getAllLoopers, getShadowMainLooper, idle, idle, idleFor, idleMainLooper, idleMainLooper, idleMainLooper, idleMainLooperConstantly, looperMode, pauseLooper, pauseMainLooper, runMainLooperOneTask, runMainLooperToNextTask, runUiThreadTasks, runUiThreadTasksIncludingDelayedTasks, shadowMainLooper, unPauseLooper, unPauseMainLooper
- 
Constructor Details- 
ShadowLegacyLooperpublic ShadowLegacyLooper()
 
- 
- 
Method Details- 
resetThreadLoopers
- 
internalInitializeBackgroundThreadSchedulerpublic static void internalInitializeBackgroundThreadScheduler()Internal API to initialize background thread scheduler from AndroidTestEnvironment.
- 
__constructor__
- 
getMainLooper
- 
myLooper
- 
loop
- 
quit
- 
quitSafely
- 
quitUncheckedpublic void quitUnchecked()- Specified by:
- quitUncheckedin class- ShadowLooper
 
- 
hasQuitpublic boolean hasQuit()- Specified by:
- hasQuitin class- ShadowLooper
 
- 
getLooperForThread
- 
getLoopersReturn loopers for all threads including main thread.
- 
idlepublic void idle()Description copied from class:ShadowLooperExecutes all posted tasks scheduled before or at the current time.- Specified by:
- idlein class- ShadowLooper
 
- 
idleForDescription copied from class:ShadowLooperAdvances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.- Specified by:
- idleForin class- ShadowLooper
 
- 
isIdlepublic boolean isIdle()Description copied from class:ShadowLooperReturns true if there are no pending tasks scheduled to be executed before current time.- Specified by:
- isIdlein class- ShadowLooper
 
- 
idleIfPausedpublic void idleIfPaused()Description copied from class: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. - Specified by:
- idleIfPausedin class- ShadowLooper
 
- 
idleConstantlypublic void idleConstantly(boolean shouldIdleConstantly) - Specified by:
- idleConstantlyin class- ShadowLooper
 
- 
runToEndOfTaskspublic void runToEndOfTasks()Description copied from class:ShadowLooperCauses all of theRunnables that have been scheduled to run while advancing the clock to the start time of the last scheduledRunnable.- Specified by:
- runToEndOfTasksin class- ShadowLooper
 
- 
runToNextTaskpublic void runToNextTask()Description copied from class:ShadowLooperCauses the nextRunnable(s) that have been scheduled to run while advancing the clock to its start time. If more than oneRunnableis scheduled to run at this time then they will all be run.- Specified by:
- runToNextTaskin class- ShadowLooper
 
- 
runOneTaskpublic void runOneTask()Description copied from class:ShadowLooperCauses only one of the nextRunnables that have been scheduled to run while advancing the clock to its start time. Only oneRunnablewill run even if more than one has been scheduled to run at the same time.- Specified by:
- runOneTaskin class- ShadowLooper
 
- 
postDeprecated.Use aHandlerinstance to post to a looper.Enqueue a task to be run later.- Specified by:
- postin class- ShadowLooper
- Parameters:
- runnable- the task to be run
- delayMillis- how many milliseconds into the (virtual) future to run it
- Returns:
- true if the runnable is enqueued
- See Also:
 
- 
postAtFrontOfQueueDeprecated.Use aHandlerinstance to post to a looper.Enqueue a task to be run ahead of all other delayed tasks.- Specified by:
- postAtFrontOfQueuein class- ShadowLooper
- Parameters:
- runnable- the task to be run
- Returns:
- true if the runnable is enqueued
- See Also:
 
- 
pausepublic void pause()Description copied from class:ShadowLooperPause the looper.Has no practical effect for realistic looper, since it is always paused. - Specified by:
- pausein class- ShadowLooper
 
- 
getNextScheduledTaskTimeDescription copied from class:ShadowLooperReturns the scheduled time of the next posted task; Duration.ZERO if there is no currently scheduled task.It is recommended to call this from the Looper's own thread, especially if calling frequently in a loop as each call may require execution on the Looper thread. Consider using one of the run* or idleFor methods instead. - Specified by:
- getNextScheduledTaskTimein class- ShadowLooper
 
- 
getLastScheduledTaskTime- Specified by:
- getLastScheduledTaskTimein class- ShadowLooper
- Returns:
- the scheduled time of the last posted task; Duration.ZERO 0 if there is no currently scheduled task.
 
- 
runUntilEmptypublic void runUntilEmpty()Description copied from class:ShadowLooperContinuously run all Messages on this Looper until its queue is empty. SystemClock is advanced to the scheduled time of last executed Message.Use with caution, as this method will never terminate if tasks are posted continuously (eg infinite animation loops). - Specified by:
- runUntilEmptyin class- ShadowLooper
 
- 
unPausepublic void unPause()Description copied from class:ShadowLooperNot supported for the main Looper inLooperMode.Mode.PAUSED.- Specified by:
- unPausein class- ShadowLooper
 
- 
isPausedpublic boolean isPaused()- Specified by:
- isPausedin class- ShadowLooper
 
- 
setPausedpublic boolean setPaused(boolean shouldPause) Description copied from class:ShadowLooperControl the paused state of the Looper.Not supported for the main Looper in LooperMode.Mode.PAUSED.- Specified by:
- setPausedin class- ShadowLooper
 
- 
resetSchedulerpublic void resetScheduler()Description copied from class:ShadowLooperOnly supported forLooperMode.Mode.LEGACY.- Specified by:
- resetSchedulerin class- ShadowLooper
 
- 
resetpublic void reset()Causes all enqueued tasks to be discarded, and pause state to be reset- Specified by:
- resetin class- ShadowLooper
 
- 
getSchedulerReturns theSchedulerthat is being used to manage the enqueued tasks. This scheduler is managed by the Looper's associated queue.- Specified by:
- getSchedulerin class- ShadowLooper
- Returns:
- the Schedulerthat is being used to manage the enqueued tasks.
 
- 
runPausedDescription copied from class:ShadowLooperRuns the current task with the looper paused.When LooperMode is PAUSED, this will execute all pending tasks scheduled before the current time. - Specified by:
- runPausedin class- ShadowLooper
 
 
- 
Handlerinstance to post to a looper.