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 ActivityNotFoundException and the Activity is missing from the test APK manifest.
  • A recreate() test "loses" state and the user is debugging remember vs rememberSaveable.
  • The user posts an action onto the UI thread and the test deadlocks (onActivity called from the wrong thread).
  • A test calls setResult(...) + finish() and wants to read the Activity.RESULT_* back.
  • The user mentions Settings.Global.ALWAYS_FINISH_ACTIVITIES ("Don't keep activities") as a way to test recreation — ActivityScenario rejects it.

When NOT to use this skill

Installs
37
GitHub Stars
319
First Seen
May 16, 2026
launching-activities-with-activityscenario — skydoves/android-testing-skills