Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After exiting app with back button Platform views on Android 14 turn blank on resume. #148662

Closed
mr-pant opened this issue May 20, 2024 · 12 comments · Fixed by flutter/engine#52980
Labels
a: platform-views Embedding Android/iOS views in Flutter apps cp: stable cherry pick this pull request to stable release candidate branch e: OS-version specific Affects only some versions of the relevant operating system platform-android Android applications specifically platform-views: tlhc Issues specific to the Android Texture Layer Hybrid Composition platform views backend r: fixed Issue is closed as already fixed in a newer version team-android Owned by Android platform team

Comments

@mr-pant
Copy link

mr-pant commented May 20, 2024

Steps to reproduce

The issue looks very similar to #146499 but the steps are different.
This is happening with Flutter 3.22.0

Environment: Samsung Galaxy A53 5G (Android 14)

Steps:

  1. Install the app and launch.
  2. From root page (with platform view), press the back button key to move app to background.
  3. Launch the app again either from launcher or from icon.

Expected results

Platform view should be rendered at home page.

Actual results

Platform view turns blank at home page.

Further, after the issue is reproduced, if you switch to another app from recent apps launcher , and then switch back again to the sample app, the platform view starts to appear again.

Code sample

Sample is same as #146499:
https://github.com/flutter/flutter/files/14917706/platform_view_test.3.zip

Code sample

Dart:

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
      final Map<String, dynamic> creationParams = <String, dynamic>{};

    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: Text("App"),
      ),
      body: AndroidView(
        viewType: "nativeView",
        layoutDirection: TextDirection.ltr,
        creationParams: creationParams,
        creationParamsCodec: const StandardMessageCodec(),
      ),
    );
  }
}

Platform side:

class MyApplication : Application() {
    private lateinit var flutterEngine : FlutterEngine

    override fun onCreate() {
        super.onCreate()

        // Instantiate a FlutterEngine.
        flutterEngine = FlutterEngine(this)

        // Start executing Dart code to pre-warm the FlutterEngine.
        flutterEngine.dartExecutor.executeDartEntrypoint(
            DartExecutor.DartEntrypoint.createDefault()
        )

        // Cache the FlutterEngine to be used by FlutterActivity.
        FlutterEngineCache
            .getInstance()
            .put("my_engine_id", flutterEngine)
    }
}

class RootActivity: Activity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        startActivity(
            FlutterActivity.CachedEngineIntentBuilder(MainActivity::class.java, "my_engine_id")
                .build(this)
        )
        finish()
    }
}

class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        flutterEngine
            .platformViewsController
            .registry
            .registerViewFactory("nativeView", NativeViewFactory())
    }
}

Screenshots or Video

Video demonstration
Screen_Recording_20240520_120641.mov

Flutter Doctor output

[✓] Flutter (Channel stable, 3.22.0, on macOS 14.4.1 23E224 darwin-arm64, locale en-IN)
    • Flutter version 3.22.0 on channel stable at /Users/rpant/Flutter/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5dcb86f68f (11 days ago), 2024-05-09 07:39:20 -0500
    • Engine revision f6344b75dc
    • Dart version 3.4.0
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
    • Android SDK at /Users/rpant/Library/Android/sdk
    • Platform android-34, build-tools 33.0.2
    • ANDROID_HOME = /Users/rpant/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.89.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.88.0

[✓] Connected device (5 available)
    • SM A536E (mobile)               • RZCTC0B6D9L                          • android-arm64  •
      Android 14 (API 34)
    • iPhone 15 Pro (mobile)          • 99935264-E514-44AE-AC05-D0ADDC217EDB • ios            •
      com.apple.CoreSimulator.SimRuntime.iOS-17-2 (simulator)
    • macOS (desktop)                 • macos                                • darwin-arm64   •
      macOS 14.4.1 23E224 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad                • darwin         •
      macOS 14.4.1 23E224 darwin-arm64
    • Chrome (web)                    • chrome                               • web-javascript •
      Google Chrome 125.0.6422.60

[✓] Network resources
    • All expected network resources are available.

• No issues found!```

@mr-pant mr-pant changed the title After exiting app with back button Platform views on Android 14 stop updating on resume. After exiting app with back button Platform views on Android 14 turn blank on resume. May 20, 2024
@darshankawar darshankawar added the in triage Presently being triaged by the triage team label May 20, 2024
@darshankawar
Copy link
Member

The issue looks very similar to #146499 but the steps are different.

@mr-pant This issue was reported on Pixel devices which was fixed. Since you are seeing the issue on Samsung, a similar issue related to it was fixed at Samsung side itself that you can check and confirm at your end.

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 20, 2024
@mr-pant
Copy link
Author

mr-pant commented May 20, 2024

a similar issue related to it was fixed at Samsung side itself that you can check and confirm at your end.

@darshankawar , the mentioned issue is different in which the entire app stops drawing on resume. This issue is just with the platform view as you can see that the app bar is visible. Also it recovers after switch from other app. Which does not happen in the other issue. Let me know if you need any other detail to differentiate the issue.

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 20, 2024
@darshankawar
Copy link
Member

Thanks for the update @mr-pant. If you see the linked issue, it was solved at Samsung's end. Is there a way for you to check the same behavior on device other than Samsung (ex: Pixel) just to narrow down the issue is Samsung specific or not ?

This is happening with Flutter 3.22.0

If you roll back to 3.19.6 and re-run your scenario, you don't see the reported error ?

@darshankawar darshankawar added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 21, 2024
@mr-pant
Copy link
Author

mr-pant commented May 21, 2024

@darshankawar

same behavior on device other than Samsung (ex: Pixel)

The issue happens on Pixel 7 (Android 14) as well.

Recording:

screen-20240521-172714.mov

If you roll back to 3.19.6 and re-run your scenario, you don't see the reported error ?

I am able to see the issue with 3.19.6 as well but that could also be due to #146499

@github-actions github-actions bot removed the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label May 21, 2024
@reidbaker reidbaker added a: platform-views Embedding Android/iOS views in Flutter apps platform-views: tlhc Issues specific to the Android Texture Layer Hybrid Composition platform views backend labels May 21, 2024
@reidbaker
Copy link
Contributor

Thank you for filing this bug. @darshankawar the issue has been fixed on the pixel side but that fix has not been deployed to devices yet. It is currently scheduled for the July release of android on pixel. Still working with other manufacturers.

@johnmccutchan
Copy link
Contributor

I just tried reproducing on Android 14 using Flutter master.

See attached video:

Screen.Recording.2024-05-21.at.2.07.23.PM.mov

@johnmccutchan
Copy link
Contributor

I also could not reproduce on 3.22:

$ flutter --version
Flutter 3.22.0 • channel stable • git@github.com:flutter/flutter.git
Framework • revision 5dcb86f68f (12 days ago) • 2024-05-09 07:39:20 -0500
Engine • revision f6344b75dc
Tools • Dart 3.4.0 • DevTools 2.34.3

@johnmccutchan
Copy link
Contributor

The above two tests were against an emulator. Trying on a Pixel 7 Android 14 phone.

@johnmccutchan
Copy link
Contributor

I can reproduce on my physical device. Digging in.

@johnmccutchan
Copy link
Contributor

I've reproduced the issue and have a fix (but I don't like the fix...)

This appears to be another instance of the underlying Android bug discussed here.

Waiting to hear back from the Android folks on this.

@johnmccutchan
Copy link
Contributor

Just documenting the difference between this bug and #146499:

#146499:

  • App is launched
  • App is backgrounded (via a swipe up)
  • Android Bug triggers HERE
  • onTrimMemory callback fires in Flutter and we work around the bug above.
  • App is resumed
  • Platform views render correctly

#148662:

  • App is launched
  • App is backgrounded (via a back-gesture swipe)
  • Android Bug triggers HERE
  • no onTrimMemory callback fires
  • App is resumed
  • Platform views don't render

So, with the back-gesture the onTrimMemory callback doesn't fire but with the up-gesture it does.

@darshankawar darshankawar added e: OS-version specific Affects only some versions of the relevant operating system platform-android Android applications specifically team-android Owned by Android platform team and removed in triage Presently being triaged by the triage team labels May 22, 2024
@johnmccutchan
Copy link
Contributor

Note, we will include this fix in a 3.22.x point release.

@reidbaker reidbaker added the cp: stable cherry pick this pull request to stable release candidate branch label May 22, 2024
@darshankawar darshankawar added the r: fixed Issue is closed as already fixed in a newer version label May 23, 2024
auto-submit bot pushed a commit to flutter/engine that referenced this issue May 31, 2024
…14 (#52982)

This pull request is created by [automatic cherry pick workflow](https://github.com/flutter/flutter/wiki/Flutter-Cherrypick-Process#automatically-creates-a-cherry-pick-request)
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
### Issue Link

Fixes flutter/flutter#148662
CP bug flutter/flutter#148885

### Target

stable

### PR Link

TBD

### Changelog Description

Platform view fix for android 14 when multiple activities are used and onMemoryTrim is called. 

### Impacted Users

Users shipping flutter apps on android 14 that use platform viewss 

### Impact Description

Platform views stop rendering new frames. 

### Workaround

No app level work around. 

### Risk

low

### Test Coverage

no

### Validation Steps

App is launched
App is backgrounded (via a back-gesture swipe)
Android Bug triggers HERE
no onTrimMemory callback fires
App is resumed
Platform views don't render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: platform-views Embedding Android/iOS views in Flutter apps cp: stable cherry pick this pull request to stable release candidate branch e: OS-version specific Affects only some versions of the relevant operating system platform-android Android applications specifically platform-views: tlhc Issues specific to the Android Texture Layer Hybrid Composition platform views backend r: fixed Issue is closed as already fixed in a newer version team-android Owned by Android platform team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants