{% setvar book_path %}/reference/kotlin/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}
class ActivityScenarioRule<A : Activity?> : ExternalResource
ActivityScenarioRule launches a given activity before the test starts and closes after the test.
You can access the androidx.test.core.app.ActivityScenario instance via getScenario. You may finish your activity manually in your test, it will not cause any problems and this rule does nothing after the test in such cases.
This rule is an upgraded version of the now deprecated .
This rule does not support calling scenario.getResult(). Use ActivityScenario.launchActivityForResult() when the Activity result is needed.
Example:
@Rule
public ActivityScenarioRule<MyActivity> rule =
new ActivityScenarioRule<>(MyActivity.class);
@Test
public void myTest() {
ActivityScenario<MyActivity> scenario = rule.getScenario();
// Your test code goes here.
}
Public constructors |
|
|---|---|
ActivityScenarioRule(activityClass: Class<A!>!)Constructs ActivityScenarioRule for a given activity class. |
|
ActivityScenarioRule(startActivityIntent: Intent!)Constructs ActivityScenarioRule with a given intent. |
|
ActivityScenarioRule(activityClass: Class<A!>!, activityOptions: Bundle?) |
|
ActivityScenarioRule( |
|
Public properties |
|
|---|---|
ActivityScenario<A!>? |
|
Inherited functions |
||
|---|---|---|
|
||
ActivityScenarioRule(activityClass: Class<A!>!)
Constructs ActivityScenarioRule for a given activity class.
| Parameters | |
|---|---|
activityClass: Class<A!>! |
an activity class to launch |
ActivityScenarioRule(startActivityIntent: Intent!)
Constructs ActivityScenarioRule with a given intent.
| Parameters | |
|---|---|
startActivityIntent: Intent! |
an intent to start an activity |
ActivityScenarioRule(activityClass: Class<A!>!, activityOptions: Bundle?)
| Parameters | |
|---|---|
activityOptions: Bundle? |
an activity options bundle to be passed along with the intent to start activity. |
| See also | |
|---|---|
ActivityScenarioRule |
|
ActivityScenarioRule(
startActivityIntent: Intent!,
activityOptions: Bundle?
)
| Parameters | |
|---|---|
activityOptions: Bundle? |
an activity options bundle to be passed along with the intent to start activity. |
| See also | |
|---|---|
ActivityScenarioRule |
|