From 37de638a9d3edcf1d0c8674b2f2c1b5f3f30758d Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Fri, 7 Feb 2020 16:35:19 -0800 Subject: [PATCH 1/2] Prevent long flash when switching to Flutter app. (#47903) --- .../FlutterActivityAndFragmentDelegate.java | 44 +++++++------------ 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java b/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java index 4ca426491afa1..40d3407a4aefe 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java @@ -12,7 +12,6 @@ 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; @@ -235,11 +234,16 @@ void onAttach(@NonNull Context context) { /** * Invoke this method from {@code Activity#onCreate(Bundle)} to create the content {@code View}, * or from {@code Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)}. - * - *

{@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. + *

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

+ * This method: + *

    + *
  1. creates a new {@link FlutterView} in a {@code View} hierarchy
  2. + *
  3. adds a {@link FlutterUiDisplayListener} to it
  4. + *
  5. attaches a {@link FlutterEngine} to the new {@link FlutterView}
  6. + *
  7. returns the new {@code View} hierarchy
  8. + *
*/ @NonNull View onCreateView( @@ -261,6 +265,9 @@ View onCreateView( } flutterSplashView.displayFlutterViewWithSplash(flutterView, host.provideSplashScreen()); + Log.v(TAG, "Attaching FlutterEngine to FlutterView."); + flutterView.attachToFlutterEngine(flutterEngine); + return flutterSplashView; } @@ -281,31 +288,13 @@ void onActivityCreated(@Nullable Bundle bundle) { *

* *

    - *
  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. + *
  3. Begins executing Dart code, if it is not already executing.
  4. *
*/ 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 +407,6 @@ void onStop() { Log.v(TAG, "onStop()"); ensureAlive(); flutterEngine.getLifecycleChannel().appIsPaused(); - flutterView.detachFromFlutterEngine(); } /** @@ -429,6 +417,8 @@ void onStop() { void onDestroyView() { Log.v(TAG, "onDestroyView()"); ensureAlive(); + + flutterView.detachFromFlutterEngine(); flutterView.removeOnFirstFrameRenderedListener(flutterUiDisplayListener); } From f5d90263b7c03d1fe9066ca8e05387bfdf77e377 Mon Sep 17 00:00:00 2001 From: Matt Carroll Date: Mon, 10 Feb 2020 15:02:39 -0800 Subject: [PATCH 2/2] Formatting fixes. --- .../FlutterActivityAndFragmentDelegate.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java b/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java index 40d3407a4aefe..24689fc40ace1 100644 --- a/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java +++ b/shell/platform/android/io/flutter/embedding/android/FlutterActivityAndFragmentDelegate.java @@ -234,15 +234,16 @@ void onAttach(@NonNull Context context) { /** * Invoke this method from {@code Activity#onCreate(Bundle)} to create the content {@code View}, * or from {@code Fragment#onCreateView(LayoutInflater, ViewGroup, Bundle)}. - *

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

- * This method: + * + *

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

This method: + * *

    - *
  1. creates a new {@link FlutterView} in a {@code View} hierarchy
  2. - *
  3. adds a {@link FlutterUiDisplayListener} to it
  4. - *
  5. attaches a {@link FlutterEngine} to the new {@link FlutterView}
  6. - *
  7. returns the new {@code View} hierarchy
  8. + *
  9. creates a new {@link FlutterView} in a {@code View} hierarchy + *
  10. adds a {@link FlutterUiDisplayListener} to it + *
  11. attaches a {@link FlutterEngine} to the new {@link FlutterView} + *
  12. returns the new {@code View} hierarchy *
*/ @NonNull @@ -288,7 +289,7 @@ void onActivityCreated(@Nullable Bundle bundle) { *

* *

    - *
  1. Begins executing Dart code, if it is not already executing.
  2. + *
  3. Begins executing Dart code, if it is not already executing. *
*/ void onStart() {