Package org.robolectric.util
Class Scheduler
java.lang.Object
org.robolectric.util.Scheduler
- Direct Known Subclasses:
LooperDelegatingScheduler
Deprecated.
Class that manages a queue of Runnables that are scheduled to run now (or at some time in the
future). Runnables that are scheduled to run on the UI thread (tasks, animations, etc) eventually
get routed to a Scheduler instance.
The execution of a scheduler can be in one of three states:
- paused (
pause()
): if paused, then no posted events will be run unless the Scheduler is explicitly instructed to do so, correctly matching Android's behavior. - normal (
unPause()
): if not paused but not set to idle constantly, then the Scheduler will automatically run anyRunnable
s that are scheduled to run at or before the Scheduler's current time, but it won't automatically run any future events. To run future events the Scheduler needs to have its clock advanced. - idling constantly: if
idleConstantly(boolean)
is called with true, then the Scheduler will continue looping through posted events (including future events), advancing its clock as it goes.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Deprecated.Describes the current state of aScheduler
. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
advanceBy
(long interval) Deprecated.boolean
Deprecated.Run all runnables that are scheduled to run in the next time interval.boolean
advanceTo
(long endTime) Deprecated.Run all runnables that are scheduled before the endTime.boolean
Deprecated.Run all runnables in the queue, and any additional runnables they schedule that are scheduled before the latest scheduled runnable currently in the queue.boolean
Deprecated.Run the next runnable in the queue.boolean
Deprecated.Determine if any enqueued runnables are enqueued before the current time.long
Deprecated.Get the current time (as seen by the scheduler), in milliseconds.Deprecated.Retrieves the current idling state of thisScheduler
.Deprecated.Deprecated.void
idleConstantly
(boolean shouldIdleConstantly) Deprecated.This method is ambiguous in how it should behave when turning off constant idle.boolean
isPaused()
Deprecated.Determine if the scheduler is paused.void
pause()
Deprecated.Pause the scheduler.void
Deprecated.Add a runnable to the queue.void
postAtFrontOfQueue
(Runnable runnable) Deprecated.Add a runnable to the head of the queue.void
postDelayed
(Runnable runnable, long delayMillis) Deprecated.Add a runnable to the queue to be run after a delay.void
postDelayed
(Runnable runnable, long delay, TimeUnit unit) Deprecated.Add a runnable to the queue to be run after a delay.void
Deprecated.Remove a runnable from the queue.void
reset()
Deprecated.Reset the internal state of the Scheduler.boolean
Deprecated.Run the next runnable in the queue.void
setIdleState
(Scheduler.IdleState idleState) Deprecated.Sets the current idling state of thisScheduler
.int
size()
Deprecated.Return the number of enqueued runnables.void
unPause()
Deprecated.Un-pause the scheduler.
-
Constructor Details
-
Scheduler
public Scheduler()Deprecated.
-
-
Method Details
-
getIdleState
Deprecated.Retrieves the current idling state of thisScheduler
.- Returns:
- The current idle state of this
Scheduler
. - See Also:
-
setIdleState
Deprecated.Sets the current idling state of thisScheduler
. If transitioning to theScheduler.IdleState.UNPAUSED
state any tasks scheduled to be run at or before the current time will be run, and if transitioning to theScheduler.IdleState.CONSTANT_IDLE
state all scheduled tasks will be run and the clock advanced to the time of the last runnable.- Parameters:
idleState
- The new idle state of thisScheduler
.- See Also:
-
getCurrentTime
public long getCurrentTime()Deprecated.Get the current time (as seen by the scheduler), in milliseconds.- Returns:
- Current time in milliseconds.
-
pause
public void pause()Deprecated.Pause the scheduler. Equivalent tosetIdleState(PAUSED)
.- See Also:
-
unPause
public void unPause()Deprecated.Un-pause the scheduler. Equivalent tosetIdleState(UNPAUSED)
.- See Also:
-
isPaused
public boolean isPaused()Deprecated.Determine if the scheduler is paused.- Returns:
- true if it is paused.
-
post
Deprecated.Add a runnable to the queue.- Parameters:
runnable
- Runnable to add.
-
postDelayed
Deprecated.Add a runnable to the queue to be run after a delay.- Parameters:
runnable
- Runnable to add.delayMillis
- Delay in millis.
-
postDelayed
Deprecated.Add a runnable to the queue to be run after a delay. -
postAtFrontOfQueue
Deprecated.Add a runnable to the head of the queue.- Parameters:
runnable
- Runnable to add.
-
remove
Deprecated.Remove a runnable from the queue.- Parameters:
runnable
- Runnable to remove.
-
advanceToLastPostedRunnable
public boolean advanceToLastPostedRunnable()Deprecated.Run all runnables in the queue, and any additional runnables they schedule that are scheduled before the latest scheduled runnable currently in the queue.- Returns:
- True if a runnable was executed.
-
advanceToNextPostedRunnable
public boolean advanceToNextPostedRunnable()Deprecated.Run the next runnable in the queue.- Returns:
- True if a runnable was executed.
-
advanceBy
@InlineMe(replacement="this.advanceBy(interval, MILLISECONDS)", staticImports="java.util.concurrent.TimeUnit.MILLISECONDS") @Deprecated public final boolean advanceBy(long interval) Deprecated.Run all runnables that are scheduled to run in the next time interval.- Parameters:
interval
- Time interval (in millis).- Returns:
- True if a runnable was executed.
-
advanceBy
Deprecated.Run all runnables that are scheduled to run in the next time interval.- Returns:
- True if a runnable was executed.
-
advanceTo
public boolean advanceTo(long endTime) Deprecated.Run all runnables that are scheduled before the endTime.- Parameters:
endTime
- Future time.- Returns:
- True if a runnable was executed.
-
runOneTask
public boolean runOneTask()Deprecated.Run the next runnable in the queue.- Returns:
- True if a runnable was executed.
-
areAnyRunnable
public boolean areAnyRunnable()Deprecated.Determine if any enqueued runnables are enqueued before the current time.- Returns:
- True if any runnables can be executed.
-
reset
public void reset()Deprecated.Reset the internal state of the Scheduler. -
size
public int size()Deprecated.Return the number of enqueued runnables.- Returns:
- Number of enqueues runnables.
-
getNextScheduledTaskTime
Deprecated. -
getLastScheduledTaskTime
Deprecated. -
idleConstantly
Deprecated.This method is ambiguous in how it should behave when turning off constant idle. UsesetIdleState(IdleState)
instead to explicitly set the state.Set the idle state of the Scheduler. If necessary, the clock will be advanced and runnables executed as required by the newly-set state.- Parameters:
shouldIdleConstantly
- If true the idle state will be set toScheduler.IdleState.CONSTANT_IDLE
, otherwise it will be set toScheduler.IdleState.UNPAUSED
.
-
ShadowLooper
APIs instead.