ShadowLegacyLooper
, ShadowPausedLooper
@Implements(value=android.os.Looper.class, shadowPicker=Picker.class) public abstract class ShadowLooper extends Object
It will delegate calls to the appropriate shadow based on the current LooperMode.
Modifier and Type | Class | Description |
---|---|---|
static class |
ShadowLooper.Picker |
Constructor | Description |
---|---|
ShadowLooper() |
Modifier and Type | Method | Description |
---|---|---|
static void |
assertLooperMode(LooperMode.Mode expectedMode) |
|
static void |
clearLooperMode() |
|
static Collection<Looper> |
getAllLoopers() |
Return all created loopers.
|
abstract Duration |
getLastScheduledTaskTime() |
|
static Looper |
getLooperForThread(Thread thread) |
|
abstract Duration |
getNextScheduledTaskTime() |
|
abstract Scheduler |
getScheduler() |
Returns the
Scheduler that is being used to manage the enqueued
tasks. |
static ShadowLooper |
getShadowMainLooper() |
Deprecated.
Use
shadowOf({@link Looper#getMainLooper()}) instead. |
abstract boolean |
hasQuit() |
|
abstract 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) |
Deprecated.
use
idleFor(amount, unit) |
abstract void |
idleConstantly(boolean shouldIdleConstantly) |
|
abstract 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 |
idleFor(Duration duration) |
A variant of
idleFor(long, TimeUnit) that accepts a Duration. |
abstract void |
idleIfPaused() |
Helper method to selectively call idle() only if LooperMode is PAUSED.
|
static void |
idleMainLooper() |
|
static void |
idleMainLooper(long interval) |
Deprecated.
|
static void |
idleMainLooper(long amount,
TimeUnit unit) |
|
static void |
idleMainLooperConstantly(boolean shouldIdleConstantly) |
|
abstract boolean |
isIdle() |
Returns true if there are no pending tasks scheduled to be executed before current time.
|
abstract boolean |
isPaused() |
|
static LooperMode.Mode |
looperMode() |
Return the current
LooperMode . |
abstract void |
pause() |
Pause the looper.
|
static void |
pauseLooper(Looper looper) |
Pauses execution of tasks posted to the ShadowLegacyLooper.
|
static void |
pauseMainLooper() |
Puts the main ShadowLegacyLooper in an "paused" state.
|
abstract boolean |
post(Runnable runnable,
long delayMillis) |
Deprecated.
Use a
Handler instance to post to a looper. |
abstract boolean |
postAtFrontOfQueue(Runnable runnable) |
Deprecated.
Use a
Handler instance to post to a looper. |
abstract void |
quitUnchecked() |
|
abstract void |
reset() |
Causes all enqueued tasks to be discarded, and pause state to be reset
|
abstract void |
resetScheduler() |
Only supported for
LooperMode.Mode.LEGACY . |
static void |
resetThreadLoopers() |
Should not be called directly - Robolectric internal use only.
|
static void |
runMainLooperOneTask() |
|
static void |
runMainLooperToNextTask() |
|
abstract void |
runOneTask() |
Causes only one of the next
Runnable s that have been scheduled to run while advancing
the clock to its start time. |
abstract void |
runPaused(Runnable run) |
Runs the current task with the looper paused.
|
abstract void |
runToEndOfTasks() |
|
abstract void |
runToNextTask() |
Causes the next
Runnable (s) that have been scheduled to run while advancing the clock
to its start time. |
static void |
runUiThreadTasks() |
Runs any immediately runnable tasks previously queued on the UI thread, e.g.
|
static void |
runUiThreadTasksIncludingDelayedTasks() |
Runs all runnable tasks (pending and future) that have been queued on the UI thread.
|
abstract boolean |
setPaused(boolean shouldPause) |
Control the paused state of the Looper.
|
static ShadowLooper |
shadowMainLooper() |
|
abstract void |
unPause() |
Not supported for the main Looper in
LooperMode.Mode.PAUSED . |
static void |
unPauseLooper(Looper looper) |
Puts the shadow looper in an "unpaused" state (this is the default state).
|
static void |
unPauseMainLooper() |
Puts the main ShadowLegacyLooper in an "unpaused" state.
|
public static void assertLooperMode(LooperMode.Mode expectedMode)
@Deprecated public static ShadowLooper getShadowMainLooper()
shadowOf({@link Looper#getMainLooper()})
instead.public static ShadowLooper shadowMainLooper()
public static Collection<Looper> getAllLoopers()
public static void resetThreadLoopers()
public static LooperMode.Mode looperMode()
LooperMode
.@Resetter public static void clearLooperMode()
public static void pauseLooper(Looper looper)
#runToEndOftasks
or a similar method, otherwise they will not run at all before your test
ends.looper
- the looper to pausepublic static void unPauseLooper(Looper looper)
looper
- the looper to pausepublic static void pauseMainLooper()
pauseLooper(android.os.Looper)
public static void unPauseMainLooper()
unPauseLooper(android.os.Looper)
public static void idleMainLooper()
@Deprecated public static void idleMainLooper(long interval)
idleMainLooper(long, TimeUnit)
.public static void idleMainLooper(long amount, TimeUnit unit)
public static void idleMainLooperConstantly(boolean shouldIdleConstantly)
public static void runMainLooperOneTask()
public static void runMainLooperToNextTask()
public static void runUiThreadTasks()
Activity.runOnUiThread(Runnable)
or AsyncTask.onPostExecute(Object)
.
**Note:** calling this method does not pause or un-pause the scheduler.
runUiThreadTasksIncludingDelayedTasks()
public static void runUiThreadTasksIncludingDelayedTasks()
Activity.runOnUiThread(Runnable)
or AsyncTask.onPostExecute(Object)
.
**Note:** calling this method does not pause or un-pause the scheduler, however the clock is advanced as future tasks are run.
runUiThreadTasks()
public abstract void quitUnchecked()
public abstract boolean hasQuit()
public abstract void idle()
public abstract void idleFor(long time, TimeUnit timeUnit)
public void idleFor(Duration duration)
idleFor(long, TimeUnit)
that accepts a Duration.public abstract boolean isIdle()
public abstract void unPause()
LooperMode.Mode.PAUSED
.public abstract boolean isPaused()
public abstract boolean setPaused(boolean shouldPause)
Not supported for the main Looper in LooperMode.Mode.PAUSED
.
public abstract void resetScheduler()
LooperMode.Mode.LEGACY
.public abstract void reset()
public abstract Scheduler getScheduler()
Scheduler
that is being used to manage the enqueued
tasks. This scheduler is managed by the Looper's associated queue.
Only supported for LooperMode.Mode.LEGACY
.
Scheduler
that is being used to manage the enqueued
tasks.public abstract void runPaused(Runnable run)
When LooperMode is PAUSED, this will execute all pending tasks scheduled before the current time.
public abstract void idleIfPaused()
Intended for backwards compatibility, to avoid changing behavior for tests still using LEGACY LooperMode.
@Deprecated public void idle(long intervalMillis)
idle(long, TimeUnit)
.Runnable
s that have been scheduled to run within the next intervalMillis
milliseconds to run while advancing the scheduler's clock.@Deprecated public void idle(long amount, TimeUnit unit)
idleFor(amount, unit)
Runnable
s that have been scheduled to run within the next specified amount of
time to run while advancing the clock.public abstract void idleConstantly(boolean shouldIdleConstantly)
public abstract void runToEndOfTasks()
public abstract void runToNextTask()
public abstract void runOneTask()
@Deprecated public abstract boolean post(Runnable runnable, long delayMillis)
Handler
instance to post to a looper.runnable
- the task to be rundelayMillis
- how many milliseconds into the (virtual) future to run itHandler.postDelayed(Runnable,long)
@Deprecated public abstract boolean postAtFrontOfQueue(Runnable runnable)
Handler
instance to post to a looper.runnable
- the task to be runHandler.postAtFrontOfQueue(Runnable)
public abstract void pause()
Has no practical effect for realistic looper, since it is always paused.
public abstract Duration getNextScheduledTaskTime()
public abstract Duration getLastScheduledTaskTime()