Package org.robolectric.shadows
Class ShadowLegacyLooper
java.lang.Object
org.robolectric.shadows.ShadowLooper
org.robolectric.shadows.ShadowLegacyLooper
@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().
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.robolectric.shadows.ShadowLooper
ShadowLooper.Picker -
Constructor Summary
Constructors -
Method Summary
Modifier 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 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.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.ShadowLooper
assertLooperMode, clearLooperMode, getAllLoopers, getShadowMainLooper, idle, idle, idleFor, idleMainLooper, idleMainLooper, idleMainLooper, idleMainLooperConstantly, looperMode, pauseLooper, pauseMainLooper, runMainLooperOneTask, runMainLooperToNextTask, runUiThreadTasks, runUiThreadTasksIncludingDelayedTasks, shadowMainLooper, unPauseLooper, unPauseMainLooper
-
Constructor Details
-
ShadowLegacyLooper
public ShadowLegacyLooper()
-
-
Method Details
-
resetThreadLoopers
-
internalInitializeBackgroundThreadScheduler
public static void internalInitializeBackgroundThreadScheduler()Internal API to initialize background thread scheduler from AndroidTestEnvironment. -
__constructor__
-
getMainLooper
-
myLooper
-
loop
-
quit
-
quitSafely
-
quitUnchecked
public void quitUnchecked()- Specified by:
quitUncheckedin classShadowLooper
-
hasQuit
public boolean hasQuit()- Specified by:
hasQuitin classShadowLooper
-
getLooperForThread
-
getLoopers
Return loopers for all threads including main thread. -
idle
public void idle()Description copied from class:ShadowLooperExecutes all posted tasks scheduled before or at the current time.- Specified by:
idlein classShadowLooper
-
idleFor
Description 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 classShadowLooper
-
isIdle
public boolean isIdle()Description copied from class:ShadowLooperReturns true if there are no pending tasks scheduled to be executed before current time.- Specified by:
isIdlein classShadowLooper
-
idleIfPaused
public 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 classShadowLooper
-
idleConstantly
public void idleConstantly(boolean shouldIdleConstantly) - Specified by:
idleConstantlyin classShadowLooper
-
runToEndOfTasks
public 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 classShadowLooper
-
runToNextTask
public 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 classShadowLooper
-
runOneTask
public 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 classShadowLooper
-
post
Deprecated.Use aHandlerinstance to post to a looper.Enqueue a task to be run later.- Specified by:
postin classShadowLooper- Parameters:
runnable- the task to be rundelayMillis- how many milliseconds into the (virtual) future to run it- Returns:
- true if the runnable is enqueued
- See Also:
-
postAtFrontOfQueue
Deprecated.Use aHandlerinstance to post to a looper.Enqueue a task to be run ahead of all other delayed tasks.- Specified by:
postAtFrontOfQueuein classShadowLooper- Parameters:
runnable- the task to be run- Returns:
- true if the runnable is enqueued
- See Also:
-
pause
public void pause()Description copied from class:ShadowLooperPause the looper.Has no practical effect for realistic looper, since it is always paused.
- Specified by:
pausein classShadowLooper
-
getNextScheduledTaskTime
- Specified by:
getNextScheduledTaskTimein classShadowLooper- Returns:
- the scheduled time of the next posted task; Duration.ZERO if there is no currently scheduled task.
-
getLastScheduledTaskTime
- Specified by:
getLastScheduledTaskTimein classShadowLooper- Returns:
- the scheduled time of the last posted task; Duration.ZERO 0 if there is no currently scheduled task.
-
unPause
public void unPause()Description copied from class:ShadowLooperNot supported for the main Looper inLooperMode.Mode.PAUSED.- Specified by:
unPausein classShadowLooper
-
isPaused
public boolean isPaused()- Specified by:
isPausedin classShadowLooper
-
setPaused
public 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 classShadowLooper
-
resetScheduler
public void resetScheduler()Description copied from class:ShadowLooperOnly supported forLooperMode.Mode.LEGACY.- Specified by:
resetSchedulerin classShadowLooper
-
reset
public void reset()Causes all enqueued tasks to be discarded, and pause state to be reset- Specified by:
resetin classShadowLooper
-
getScheduler
Returns theSchedulerthat is being used to manage the enqueued tasks. This scheduler is managed by the Looper's associated queue.- Specified by:
getSchedulerin classShadowLooper- Returns:
- the
Schedulerthat is being used to manage the enqueued tasks.
-
runPaused
Description 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 classShadowLooper
-
Handlerinstance to post to a looper.