launching-activities-with-activityscenario

Manage Android Activity lifecycle and configuration changes with ActivityScenario API.

Updated Jul 20, 2026
One-click install
npx skills add https://github.com/trancee/MeshLink-template --skill launching-activities-with-activityscenario-trancee
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: launching-activities-with-activityscenario
Source: https://github.com/trancee/MeshLink-template/tree/main/.agents/skills/android-testing-skills/instrumentation/scenarios/launching-activities-with-activityscenario
Command: npx skills add https://github.com/trancee/MeshLink-template --skill launching-activities-with-activityscenario-trancee

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill resolves the common pitfalls and confusion surrounding the migration from the deprecated ActivityTestRule to the modern, thread-safe ActivityScenario, ensuring reliable instrumentation tests.

Core Features & Use Cases

  • Lifecycle Management: Provides precise control over Activity states including CREATED, STARTED, RESUMED, and DESTROYED.
  • Configuration Change Emulation: Safely tests state restoration using the recreate method to verify ViewModel and saved instance state logic.
  • Use Case: Use this skill when you need to verify that your Activity correctly handles configuration changes or when you need to drive an Activity through specific lifecycle transitions to test UI behavior in isolation.

Quick Start

Use the launching-activities-with-activityscenario skill to set up an ActivityScenarioRule for your LoginActivity and verify that the UI state is correctly restored after a configuration change.

Frequently Asked Questions about launching-activities-with-activityscenario

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Android Activity lifecycle transitions in instrumentation tests?

Test Android Activity lifecycle transitions using the ActivityScenario API to drive an Activity through CREATED, STARTED, RESUMED, and DESTROYED states. This provides precise state control and ensures reliable instrumentation tests without thread-safety issues.

How do I emulate configuration changes to test ViewModel state restoration?

Emulate configuration changes to test ViewModel state restoration by calling the recreate method within ActivityScenario. This safely triggers Activity destruction and recreation, allowing you to verify saved instance state logic correctly restores the UI.

What is the best way to migrate from ActivityTestRule to modern Android testing?

The best way to migrate from ActivityTestRule to modern Android testing is adopting ActivityScenario. It resolves migration pitfalls by providing a thread-safe environment for launching activities, managing state transitions, and synchronizing the UI thread.

Do I need specific dependencies to use ActivityScenario for Android instrumentation testing?

Yes, you need the androidx.test.core and androidx.test.ext.junit dependencies to use ActivityScenario for Android instrumentation testing. These libraries are required to ensure canonical and thread-safe test execution during activity launching and state transitions.

Why does my UI state not restore correctly after an activity configuration change?

Your UI state might not restore correctly after an activity configuration change if your test lacks proper lifecycle management. Using ActivityScenario's recreate method ensures the Activity is safely destroyed and recreated, accurately verifying your ViewModel and saved state logic.