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 Runnable
s to be run (on this thread) later.
Runnable
s 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
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
__constructor__
(boolean quitAllowed) static Looper
getLooperForThread
(Thread thread) protected static Collection<Looper>
Return loopers for all threads including main thread.protected static Looper
Returns theScheduler
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
idleConstantly
(boolean shouldIdleConstantly) void
Advances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.void
Helper method to selectively call idle() only if LooperMode is PAUSED.static void
Internal API to initialize background thread scheduler from AndroidTestEnvironment.boolean
isIdle()
Returns true if there are no 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
Deprecated.boolean
postAtFrontOfQueue
(Runnable runnable) Deprecated.Use aHandler
instance to post to a looper.protected void
quit()
protected void
void
void
reset()
Causes all enqueued tasks to be discarded, and pause state to be resetvoid
Only supported forLooperMode.Mode.LEGACY
.static void
void
Causes only one of the nextRunnable
s that have been scheduled to run while advancing the clock to its start time.void
Runs the current task with the looper paused.void
void
Causes the nextRunnable
(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 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:
quitUnchecked
in classShadowLooper
-
hasQuit
public boolean hasQuit()- Specified by:
hasQuit
in classShadowLooper
-
getLooperForThread
-
getLoopers
Return loopers for all threads including main thread. -
idle
public void idle()Description copied from class:ShadowLooper
Executes all posted tasks scheduled before or at the current time.- Specified by:
idle
in classShadowLooper
-
idleFor
Description copied from class:ShadowLooper
Advances the system clock by the given time, then executes all posted tasks scheduled before or at the given time.- Specified by:
idleFor
in classShadowLooper
-
isIdle
public boolean isIdle()Description copied from class:ShadowLooper
Returns true if there are no pending tasks scheduled to be executed before current time.- Specified by:
isIdle
in classShadowLooper
-
idleIfPaused
public void idleIfPaused()Description copied from class:ShadowLooper
Helper 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:
idleIfPaused
in classShadowLooper
-
idleConstantly
public void idleConstantly(boolean shouldIdleConstantly) - Specified by:
idleConstantly
in classShadowLooper
-
runToEndOfTasks
public void runToEndOfTasks()Description copied from class:ShadowLooper
Causes all of theRunnable
s that have been scheduled to run while advancing the clock to the start time of the last scheduledRunnable
.- Specified by:
runToEndOfTasks
in classShadowLooper
-
runToNextTask
public void runToNextTask()Description copied from class:ShadowLooper
Causes the nextRunnable
(s) that have been scheduled to run while advancing the clock to its start time. If more than oneRunnable
is scheduled to run at this time then they will all be run.- Specified by:
runToNextTask
in classShadowLooper
-
runOneTask
public void runOneTask()Description copied from class:ShadowLooper
Causes only one of the nextRunnable
s that have been scheduled to run while advancing the clock to its start time. Only oneRunnable
will run even if more than one has been scheduled to run at the same time.- Specified by:
runOneTask
in classShadowLooper
-
post
Deprecated.Use aHandler
instance to post to a looper.Enqueue a task to be run later.- Specified by:
post
in 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 aHandler
instance to post to a looper.Enqueue a task to be run ahead of all other delayed tasks.- Specified by:
postAtFrontOfQueue
in 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:ShadowLooper
Pause the looper.Has no practical effect for realistic looper, since it is always paused.
- Specified by:
pause
in classShadowLooper
-
getNextScheduledTaskTime
- Specified by:
getNextScheduledTaskTime
in classShadowLooper
- Returns:
- the scheduled time of the next posted task; Duration.ZERO if there is no currently scheduled task.
-
getLastScheduledTaskTime
- Specified by:
getLastScheduledTaskTime
in 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:ShadowLooper
Not supported for the main Looper inLooperMode.Mode.PAUSED
.- Specified by:
unPause
in classShadowLooper
-
isPaused
public boolean isPaused()- Specified by:
isPaused
in classShadowLooper
-
setPaused
public boolean setPaused(boolean shouldPause) Description copied from class:ShadowLooper
Control the paused state of the Looper.Not supported for the main Looper in
LooperMode.Mode.PAUSED
.- Specified by:
setPaused
in classShadowLooper
-
resetScheduler
public void resetScheduler()Description copied from class:ShadowLooper
Only supported forLooperMode.Mode.LEGACY
.- Specified by:
resetScheduler
in classShadowLooper
-
reset
public void reset()Causes all enqueued tasks to be discarded, and pause state to be reset- Specified by:
reset
in classShadowLooper
-
getScheduler
Returns theScheduler
that is being used to manage the enqueued tasks. This scheduler is managed by the Looper's associated queue.- Specified by:
getScheduler
in classShadowLooper
- Returns:
- the
Scheduler
that is being used to manage the enqueued tasks.
-
runPaused
Description copied from class:ShadowLooper
Runs the current task with the looper paused.When LooperMode is PAUSED, this will execute all pending tasks scheduled before the current time.
- Specified by:
runPaused
in classShadowLooper
-
Handler
instance to post to a looper.