launching-activities-with-activityscenario
Installation
SKILL.md
Launching Activities with ActivityScenario — The Canonical ActivityTestRule Replacement
ActivityScenario is the modern replacement for the deprecated ActivityTestRule. It provides a thread-safe, lifecycle-aware handle to drive an Activity through CREATED / STARTED / RESUMED / DESTROYED, recreate it for configuration-change emulation, and post work onto its UI thread via onActivity { }. The JUnit4 wrapper ActivityScenarioRule calls launch in before and close in after. This skill encodes the canonical FQN trap, the threading rules, and the manifest requirement.
When to use this skill
- The user is starting a new instrumentation test that needs an Activity host.
- The user is migrating from
ActivityTestRule(deprecated) and asks for the replacement. - A test fails with
ActivityNotFoundExceptionand the Activity is missing from the test APK manifest. - A
recreate()test "loses" state and the user is debuggingremembervsrememberSaveable. - The user posts an action onto the UI thread and the test deadlocks (
onActivitycalled from the wrong thread). - A test calls
setResult(...) + finish()and wants to read theActivity.RESULT_*back. - The user mentions
Settings.Global.ALWAYS_FINISH_ACTIVITIES("Don't keep activities") as a way to test recreation —ActivityScenariorejects it.