A mode that more accurately models real Android's
|Modifier and Type||Method||Description|
Returns the enum constant of this type with the specified name.
Returns an array containing the constants of this enum type, in the order they are declared.
clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
@Deprecated public static final LooperMode.Mode LEGACY
There is only a single Looper thread - with tests and all posted Looper tasks executing on that thread.
There are multiple problems with this mode. Some of the major ones are:
UNPAUSEDstate will execute tasks posted to a
Looperinline synchronously. This differs from real Android behaviour, and can cause issues with code that expects/enforces that posted tasks execute in the correct order, such as RecyclerViews.
Schedulerlist of Runnables can get out of sync with the Looper's
MessageQueue, causing deadlocks or other race conditions.
Schedulerkeeps its own time value, which can get out of sync.
Loopertasks execute in the main thread, causing errors for code that enforces that it runs on a non-main
public static final LooperMode.Mode PAUSED
Conceptually LooperMode.PAUSED is similar to the LEGACY
Scheduler.IdleState.PAUSED in the following ways:
Looperare not executed automatically, and must be explicitly executed via
ShadowLooper.idle(). This guarantees execution order correctness
SystemClocktime is frozen, and can be manually advanced via Robolectric APIs.
ActivityController.setup(), will automatically idle the main
Looperhas its own thread. Tasks posted to background loopers are executed asynchronously in separate threads.
Looperuse the real
MessageQueueto store their queue of pending tasks
ShadowSystemClock. This can be explictly incremented via
SchedulerAPIs for the 'foreground' scheduler are currently supported in this mode as well, although it is recommended to switch to use ShadowLooper APIs directly.
Loopers to shadowOf(looper)
public static LooperMode.Mode values()
for (LooperMode.Mode c : LooperMode.Mode.values()) System.out.println(c);
public static LooperMode.Mode valueOf(String name)