Class RuntimeEnvironment
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic ApplicationDeprecated.Please use {#getApplication} instead.static Pathstatic ContextDeprecated.UsegetApplication()instead.
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic NumbercastNativePtr(long ptr) static Objectstatic Pathstatic intstatic ApplicationGet a reference to theApplicationunder test.static ResourceTablestatic ResourceTablestatic Class<? extends Application>static floatstatic ThreadRetrieves the main thread.static SchedulerRetrieves the current master scheduler.static StringReturns a qualifier string describing the currentConfigurationof the system resources.static StringgetQualifiers(Configuration configuration, DisplayMetrics displayMetrics) Returns a qualifier string describing the given configuration and display metrics.static ResourceTablestatic TempDirectorystatic booleanTests if the current thread is currently set as the main thread.static booleanisMainThread(Thread thread) Tests if the given thread is currently set as the main thread.static voidsetActivityThread(Object newActivityThread) static voidsetAndroidFrameworkJarPath(Path localArtifactPath) static voidsetApplicationSupplier(com.google.common.base.Supplier<Application> applicationSupplier) internal use onlystatic voidsetAppResourceTable(ResourceTable appResourceTable) static voidsetCompileTimeResourceTable(ResourceTable compileTimeResourceTable) static voidsetConfiguredApplicationClass(Class<? extends Application> clazz) static voidsetFontScale(float fontScale) static voidsetMainThread(Thread newMainThread) Sets the main thread.static voidsetMasterScheduler(Scheduler masterScheduler) Sets the current master scheduler.static voidsetQualifiers(String newQualifiers) Overrides the current device configuration.static voidsetSystemResourceTable(ResourceTable systemResourceTable) static voidsetTempDirectory(TempDirectory tempDirectory) static booleanDeprecated.Do not use.
- 
Field Details- 
systemContextDeprecated.UsegetApplication()instead. Note that unlike the alternative, this field is inherently incompatible withLazyApplication. This field may be removed in a later release
- 
applicationDeprecated.Please use {#getApplication} instead. Accessing this field directly is inherently incompatible withLazyApplicationand Robolectric makes no guarantees if a test *modifies* this field during execution.
- 
compileTimeSystemResourcesFile
 
- 
- 
Constructor Details- 
RuntimeEnvironmentpublic RuntimeEnvironment()
 
- 
- 
Method Details- 
getApplicationGet a reference to theApplicationunder test.The Application may be created a test setup time or created lazily at call time, based on the test's LazyApplicationsetting. If lazy loading is enabled, this method must be called on the main/test thread.An alternate API outside of Robolectric is androidx.test.core.app.ApplicationProvider#getApplicationContext(), which is preferable if you desire cross platform tests that work on the JVM and real Android devices.
- 
setApplicationSupplierpublic static void setApplicationSupplier(com.google.common.base.Supplier<Application> applicationSupplier) internal use only
- 
getConfiguredApplicationClass
- 
setConfiguredApplicationClass
- 
isMainThreadTests if the given thread is currently set as the main thread.- Parameters:
- thread- the thread to test.
- Returns:
- true if the specified thread is the main thread, false otherwise.
- See Also:
 
- 
isMainThreadpublic static boolean isMainThread()Tests if the current thread is currently set as the main thread.Not supported in realistic looper mode. - Returns:
- true if the current thread is the main thread, false otherwise.
 
- 
getMainThreadRetrieves the main thread. The main thread is the thread to which the main looper is attached. Defaults to the thread that initialises theRuntimeEnvironmentclass.Not supported in realistic looper mode. - Returns:
- The main thread.
- See Also:
 
- 
setMainThreadSets the main thread. The main thread is the thread to which the main looper is attached. Defaults to the thread that initialises theRuntimeEnvironmentclass.Not supported in realistic looper mode. - Parameters:
- newMainThread- the new main thread.
- See Also:
 
- 
getActivityThread
- 
setActivityThread
- 
getQualifiersReturns a qualifier string describing the currentConfigurationof the system resources.- Returns:
- a qualifier string as described (https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules)[here].
 
- 
getQualifiersReturns a qualifier string describing the given configuration and display metrics.- Parameters:
- configuration- the configuration.
- displayMetrics- the display metrics.
- Returns:
- a qualifier string as described (https://developer.android.com/guide/topics/resources/providing-resources.html#QualifierRules)[here].
 
- 
setQualifiersOverrides the current device configuration.If starts with a plus ('+'), the prior configuration is used as the base configuration, with the given changes applied additively. Otherwise, default values are used for unspecified properties, as described here. - Parameters:
- newQualifiers- the qualifiers to apply
 
- 
setFontScalepublic static void setFontScale(float fontScale) 
- 
getFontScalepublic static float getFontScale()
- 
getApiLevelpublic static int getApiLevel()
- 
castNativePtr
- 
getMasterSchedulerRetrieves the current master scheduler. This scheduler is always used by the mainLooper, and if the global scheduler option is set it is also used for the background scheduler and for all otherLoopers- Returns:
- The current master scheduler.
- See Also:
 
- 
setMasterSchedulerSets the current master scheduler. SeegetMasterScheduler()for details. Note that this method is primarily intended to be called by the Robolectric core setup code. Changing the master scheduler during a test will have unpredictable results.- Parameters:
- masterScheduler- the new master scheduler.
- See Also:
 
- 
setSystemResourceTable
- 
setAppResourceTable
- 
getSystemResourceTable
- 
getAppResourceTable
- 
setCompileTimeResourceTable
- 
getCompileTimeResourceTable
- 
setTempDirectory
- 
getTempDirectory
- 
setAndroidFrameworkJarPath
- 
getAndroidFrameworkJarPath
- 
useLegacyResourcesDeprecated.Do not use.Internal only.
 
-