Skip to content

Skip EmptyActivity launch in InstrumentationActivityInvoker on API 30+. - #2546

Merged
copybara-service[bot] merged 1 commit into
mainfrom
piper_1028569570
Nov 30, 2026
Merged

copybara-service[bot] merged 1 commit into
mainfrom
piper_1028569570

Conversation

@copybara-service

Copy link
Copy Markdown

Skip EmptyActivity launch in InstrumentationActivityInvoker on API 30+.

InstrumentationActivityInvoker.finishActivity() previously launched EmptyActivity synchronously before finishing the activity under test (and again when finishing a BootstrapActivity), which slows down ActivityScenario teardown and stalls when finishing activities on restricted or secondary displays.

Skip the EmptyActivity launch on API 30+ (Android 11+) and finish the activity directly before broadcasting cleanup intents for BootstrapActivity, ActivityResultWaiter, and any existing empty facilitator activities.

Retain the EmptyActivity workaround on API 29 and below. On API 29 and earlier, ActivityStack.finishCurrentActivityLocked() adds a PAUSED activity that is still visible behind another resumed activity (such as a dialog or translucent overlay) to mFinishingActivities and waits for an activityIdle callback that never arrives, preventing onStop() and onDestroy() from running. Android 11 (API 30) fixed this in ActivityRecord.completeFinishing() by checking whether addToFinishingAndWaitForIdle() scheduled a resume before deferring destruction.

@copybara-service
copybara-service Bot force-pushed the piper_1028569570 branch 2 times, most recently from 4f7df9b to 377520c Compare November 30, 2026 22:25
`InstrumentationActivityInvoker.finishActivity()` previously launched `EmptyActivity` synchronously before finishing the activity under test (and again when finishing a `BootstrapActivity`), which slows down `ActivityScenario` teardown and stalls when finishing activities on restricted or secondary displays.

Skip the `EmptyActivity` launch on API 30+ (Android 11+) and finish the activity directly before broadcasting cleanup intents for `BootstrapActivity`, `ActivityResultWaiter`, and any existing empty facilitator activities.

Retain the `EmptyActivity` workaround on API 29 and below. On API 29 and earlier, `ActivityStack.finishCurrentActivityLocked()` adds a `PAUSED` activity that is still visible behind another resumed activity (such as a dialog or translucent overlay) to `mFinishingActivities` and waits for an `activityIdle` callback that never arrives, preventing `onStop()` and `onDestroy()` from running. Android 11 (API 30) fixed this in `ActivityRecord.completeFinishing()` by checking whether `addToFinishingAndWaitForIdle()` scheduled a resume before deferring destruction.

PiperOrigin-RevId: 1032973839
@copybara-service
copybara-service Bot merged commit ea2ea81 into main Nov 30, 2026
6 checks passed
@copybara-service
copybara-service Bot deleted the piper_1028569570 branch November 30, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant