From d9dfa09e64a2007b44866a030ebd34dcd864e6b9 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Tue, 11 Feb 2020 15:26:27 -0800 Subject: [PATCH] Prevent long flash when switching to Flutter app. (#47903) (flutter/engine#16527) --- .../FlutterActivityAndFragmentDelegate.java | 37 +++++++------------ 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java index 4ca426491af..24689fc40ac 100644 --- a/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java +++ b/engine/src/flutter/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java @@ -12,7 +12,6 @@ import android.content.Context; import android.content.Intent; import android.os.Build; import android.os.Bundle; -import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.VisibleForTesting; @@ -238,8 +237,14 @@ import java.util.Arrays; * *

{@code inflater} and {@code container} may be null when invoked from an {@code Activity}. * - *

This method creates a new {@link FlutterView}, adds a {@link FlutterUiDisplayListener} to - * it, and then returns it. + *

This method: + * + *

    + *
  1. creates a new {@link FlutterView} in a {@code View} hierarchy + *
  2. adds a {@link FlutterUiDisplayListener} to it + *
  3. attaches a {@link FlutterEngine} to the new {@link FlutterView} + *
  4. returns the new {@code View} hierarchy + *
*/ @NonNull View onCreateView( @@ -261,6 +266,9 @@ import java.util.Arrays; } flutterSplashView.displayFlutterViewWithSplash(flutterView, host.provideSplashScreen()); + Log.v(TAG, "Attaching FlutterEngine to FlutterView."); + flutterView.attachToFlutterEngine(flutterEngine); + return flutterSplashView; } @@ -281,31 +289,13 @@ import java.util.Arrays; *

* *

    - *
  1. Attaches the {@link FlutterEngine} owned by this delegate to the {@link FlutterView} - * owned by this delegate. *
  2. Begins executing Dart code, if it is not already executing. *
*/ void onStart() { Log.v(TAG, "onStart()"); ensureAlive(); - - // We post() the code that attaches the FlutterEngine to our FlutterView because there is - // some kind of blocking logic on the native side when the surface is connected. That lag - // causes launching Activitys to wait a second or two before launching. By post()'ing this - // behavior we are able to move this blocking logic to after the Activity's launch. - // TODO(mattcarroll): figure out how to avoid blocking the MAIN thread when connecting a surface - new Handler() - .post( - new Runnable() { - @Override - public void run() { - Log.v(TAG, "Attaching FlutterEngine to FlutterView."); - flutterView.attachToFlutterEngine(flutterEngine); - - doInitialFlutterViewRun(); - } - }); + doInitialFlutterViewRun(); } /** @@ -418,7 +408,6 @@ import java.util.Arrays; Log.v(TAG, "onStop()"); ensureAlive(); flutterEngine.getLifecycleChannel().appIsPaused(); - flutterView.detachFromFlutterEngine(); } /** @@ -429,6 +418,8 @@ import java.util.Arrays; void onDestroyView() { Log.v(TAG, "onDestroyView()"); ensureAlive(); + + flutterView.detachFromFlutterEngine(); flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener); }