Skip to content

Destroy the example's engine when its Activity finishes - #80

Merged
codenameakshay merged 1 commit into
mainfrom
t3/destroy-engine-on-finish
Oct 16, 2026
Merged

codenameakshay merged 1 commit into
mainfrom
t3/destroy-engine-on-finish

Conversation

@codenameakshay

Copy link
Copy Markdown
Owner

Summary

The "Activity relaunch after a wallpaper change" pattern keeps one FlutterEngine across the Android 12+ dynamic-color relaunch. It never destroyed that engine, so after the user pressed Back the next launch reused it as a warm start.

  • MainActivity in the example now overrides onDestroy(). It destroys the engine and clears the reference when !isChangingConfigurations. A relaunch still keeps the engine.
  • doc/android-compatibility.md shows the same snippet. It explains that super.onDestroy() must run first, because that call detaches the engine from the Activity and its plugins. It also notes that FlutterFragmentActivity takes the same provideFlutterEngine override.

There are no plugin code changes.

Verification

  • Confirmed in the Flutter embedding source (stable, engine 06a2e2a): FlutterActivity.onDestroy() detaches the host-provided engine without destroying it. FlutterFragmentActivity has a public provideFlutterEngine(Context), and FlutterFragment defers to it.
  • Compiled MainActivity.kt with Kotlin 2.2.20 and -Werror against android.jar (API 36) and flutter_embedding_debug for that engine. No warnings.
  • Not run: a device test of the Back → cold start path, or Gradle assembly of the example app. The local aarch64 host can't configure the :app module, so CI covers assembly.

🤖 Generated with Claude Code

The engine that survives the Android 12+ wallpaper relaunch was never
destroyed, so after Back the next launch reused it as a warm start.
Destroy it in onDestroy() unless the Activity is changing
configurations, after super.onDestroy() has detached it.

Document the same override in android-compatibility.md and note that
FlutterFragmentActivity takes the same provideFlutterEngine override.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codenameakshay
codenameakshay merged commit 3c05285 into main Oct 16, 2026
6 checks passed
@codenameakshay codenameakshay mentioned this pull request Oct 16, 2026
@codenameakshay
codenameakshay deleted the t3/destroy-engine-on-finish branch October 16, 2026 19:04
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