Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

docs.flutter.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.

Learn more

Flutter 3.41 is live! Check out theFlutter 3.41 blog post!

Android ActivityControlSurface attachToActivity signature change

attachToActivity activity parameter changed to ExclusiveAppComponent instead of Activity.

Important

Summary

#
Note

If you use standard Android embedding Java classes likeFlutterActivity orFlutterFragment, and don't manually embed aFlutterView inside your own customActivity (this should be uncommon), you can stop reading.

A newActivityControlSurface method:

java
voidattachToActivity(@NonNullExclusiveAppComponent<Activity>exclusiveActivity,@NonNullLifecyclelifecycle);

is replacing the now deprecated method:

java
voidattachToActivity(@NonNullActivityactivity,@NonNullLifecyclelifecycle);

The existing deprecated method with theActivity parameter was removed in Flutter 2.

Context

#

In order for custom Activities to also supply theActivity lifecycle events Flutter plugins expect using theActivityAware interface, theFlutterEngine exposed agetActivityControlSurface() API.

This allows custom Activities to signal to the engine (with which it has a(0|1):1 relationship) that it was being attached or detached from the engine.

Note

However, the previous API had the flaw that it didn't enforce exclusion between activities connecting to the engine, thus enablingn:1 relationships between the activity and the engine, causing lifecycle cross-talk issues.

Description of change

#

AfterIssue #21272, instead of attaching your activity to theFlutterEngine by using the:

java
voidattachToActivity(@NonNullActivityactivity,@NonNullLifecyclelifecycle);

API, which is now deprecated, instead use:

java
voidattachToActivity(@NonNullExclusiveAppComponent<Activity>exclusiveActivity,@NonNullLifecyclelifecycle);

AnExclusiveAppComponent<Activity> interface is now expected instead of anActivity. TheExclusiveAppComponent<Activity> provides a callback in case your exclusive activity is being replaced by another activity attaching itself to theFlutterEngine.

java
voiddetachFromActivity();

API remains unchanged and you're still expected to call it when your custom activity is being destroyed naturally.

Migration guide

#

If you have your own activity holding aFlutterView, replace calls to:

java
voidattachToActivity(@NonNullActivityactivity,@NonNullLifecyclelifecycle);

with calls to:

java
voidattachToActivity(@NonNullExclusiveAppComponent<Activity>exclusiveActivity,@NonNullLifecyclelifecycle);

on theActivityControlSurface that you obtained by callinggetActivityControlSurface() on theFlutterEngine.

Wrap your activity with anExclusiveAppComponent<Activity> and implement the callback method:

java
voiddetachFromFlutterEngine();

to handle your activity being replaced by another activity being attached to theFlutterEngine. Generally, you want to perform the same detaching operations as performed when the activity is being naturally destroyed.

Timeline

#

Landed in version: 1.23.0-7.0.pre
In stable release: 2.0.0

References

#

Motivating bug:Issue #66192—Non exclusive UI components attached to the FlutterEngine causes event crosstalk

Was this page's content helpful?

Unless stated otherwise, the documentation on this site reflects Flutter 3.38.6. Page last updated on 2025-10-28.View source orreport an issue.


[8]ページ先頭

©2009-2026 Movatter.jp