This class is deprecated.
use ActivityScenario or ActivityScenarioRule instead. They offer a simpler, and safer
way of controlling Activity lifecycles.
Here are some tips to consider when converting to ActivityScenario/Rule:
For simple cases where you want to launch the Activity before each test and tear it
down after each test (eg you are using ActivityTestRule(Class)), convert
directly to ActivityScenarioRule.
If you need control over when to launch the Activity (eg you are using ERROR(/#ActivityTestRule(Class, false, false)), use ActivityScenario.launch. Its recommended
to wrap the launch in a try-block, so the Activity is closed automatically.
try (ActivityScenario.launch(activityClass)) {
...
}
If you need access to the Activity during the test (eg you are calling getActivity() provide a Runnable callback to ERROR(/androidx.test.core.app.ActivityScenario#onActivity(Runnable)) instead. The callback
provided to onActivity will run on the application's main thread, thus ensuring a safer
mechanism to access the Activity.
This class is deprecated.
use UiThreadTest directly without this rule. UiThreadTest is now
supported as part of the core Android test runner to provide the ability to run methods
annotated with @Before and @After on the UI thread regardless of
what @Test is annotated with.
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2021-07-14 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]