T
- a class of the activity which is under control by this class.public class ActivityController<T extends Activity> extends ComponentController<ActivityController<T>,T>
ActivityController provides low-level APIs to control activity’s lifecycle.
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.
attached, component, intent, myself, shadowMainLooper
Modifier and Type | Method and 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> |
of(T activity) |
static <T extends Activity> |
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) |
get, getIntent, invokeWhilePaused
public static <T extends Activity> ActivityController<T> of(T activity, Intent intent)
public static <T extends Activity> ActivityController<T> of(T activity)
public ActivityController<T> create(Bundle bundle)
public ActivityController<T> create()
create
in class ComponentController<ActivityController<T extends Activity>,T extends Activity>
public ActivityController<T> restart()
public ActivityController<T> start()
public ActivityController<T> restoreInstanceState(Bundle bundle)
public ActivityController<T> postCreate(Bundle bundle)
public ActivityController<T> resume()
public ActivityController<T> postResume()
public ActivityController<T> visible()
public ActivityController<T> windowFocusChanged(boolean hasFocus)
public ActivityController<T> userLeaving()
public ActivityController<T> pause()
public ActivityController<T> saveInstanceState(Bundle outState)
public ActivityController<T> stop()
public ActivityController<T> destroy()
destroy
in class ComponentController<ActivityController<T extends Activity>,T extends Activity>
public ActivityController<T> setup()
Calls the same lifecycle methods on the Activity called by Android the first time the Activity is created.
public 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.
savedInstanceState
- Saved instance state.public ActivityController<T> newIntent(Intent intent)
public ActivityController<T> 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.
public ActivityController<T> configurationChange(Configuration newConfiguration)
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.
newConfiguration
- The new configuration to be set.public ActivityController<T> 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.