Class ActivityController<T extends Activity>
- Type Parameters:
T
- a class of the activity which is under control by this class.
public class ActivityController<T extends Activity> extends ComponentController<ActivityController<T>,T>
Using ActivityController directly from your tests is strongly discouraged. You have to call
all the lifecycle callback methods (create, postCreate, start, ...) in the same manner as the
Android framework by yourself otherwise you'll see fidelity issues. Consider using androidx.test.core.app.ActivityScenario
instead, which provides higher-level, streamlined APIs
to control the lifecycle and it works with instrumentation tests too.
-
Field Summary
Fields inherited from class org.robolectric.android.controller.ComponentController
attached, component, intent, myself, shadowMainLooper
-
Method Summary
Modifier and Type Method Description ActivityController<T>
configurationChange()
Applies the current system configuration to the Activity.ActivityController<T>
configurationChange(Configuration newConfiguration)
Performs a configuration change on the Activity.ActivityController<T>
create()
ActivityController<T>
create(Bundle bundle)
ActivityController<T>
destroy()
ActivityController<T>
newIntent(Intent intent)
static <T extends Activity>
ActivityController<T>of(T activity)
static <T extends Activity>
ActivityController<T>of(T activity, Intent intent)
ActivityController<T>
pause()
ActivityController<T>
postCreate(Bundle bundle)
ActivityController<T>
postResume()
ActivityController<T>
recreate()
Recreates activity instance which is controlled by this ActivityController.ActivityController<T>
restart()
ActivityController<T>
restoreInstanceState(Bundle bundle)
ActivityController<T>
resume()
ActivityController<T>
saveInstanceState(Bundle outState)
ActivityController<T>
setup()
Calls the same lifecycle methods on the Activity called by Android the first time the Activity is created.ActivityController<T>
setup(Bundle savedInstanceState)
Calls the same lifecycle methods on the Activity called by Android when an Activity is restored from previously saved state.ActivityController<T>
start()
ActivityController<T>
stop()
ActivityController<T>
userLeaving()
ActivityController<T>
visible()
ActivityController<T>
windowFocusChanged(boolean hasFocus)
Methods inherited from class org.robolectric.android.controller.ComponentController
get, getIntent, invokeWhilePaused, invokeWhilePaused
-
Method Details
-
of
-
of
-
create
-
create
- Specified by:
create
in classComponentController<ActivityController<T extends Activity>,T extends Activity>
-
restart
-
start
-
restoreInstanceState
-
postCreate
-
resume
-
postResume
-
visible
-
windowFocusChanged
-
userLeaving
-
pause
-
saveInstanceState
-
stop
-
destroy
- Specified by:
destroy
in classComponentController<ActivityController<T extends Activity>,T extends Activity>
-
setup
Calls the same lifecycle methods on the Activity called by Android the first time the Activity is created.- Returns:
- Activity controller instance.
-
setup
Calls the same lifecycle methods on the Activity called by Android when an Activity is restored from previously saved state.- Parameters:
savedInstanceState
- Saved instance state.- Returns:
- Activity controller instance.
-
newIntent
-
configurationChange
Applies the current system configuration to the Activity.This can be used in conjunction with
RuntimeEnvironment.setQualifiers(String)
to simulate configuration changes.If the activity is configured to handle changes without being recreated,
Activity.onConfigurationChanged(Configuration)
will be called. Otherwise, the activity is recreated as described here.- Returns:
- ActivityController instance
-
configurationChange
Performs a configuration change on the Activity.If the activity is configured to handle changes without being recreated,
Activity.onConfigurationChanged(Configuration)
will be called. Otherwise, the activity is recreated as described here.- Parameters:
newConfiguration
- The new configuration to be set.- Returns:
- ActivityController instance
-
recreate
Recreates activity instance which is controlled by this ActivityController. NonConfigurationInstances and savedInstanceStateBundle are properly passed into a new instance. After the recreation, it brings back its lifecycle state to the original state. The activity should not be destroyed yet.
-