-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
[Android] App shows black screen after being in the background. #93276
Comments
Hi @vanth0me, Thanks for filing the issue.
Can you please share some more details
|
Thank you for your response! |
Sure please verify and let us know and also please check the android version of the devices to make sure if this is/ is not related to the OS version. |
Yes will do. My emulator is running Android 12 and the devices are running Android 11. |
I am, for now, at least unable to trigger a black screen in the New Flutter Project app. I wonder if it has something to do with more memory usage. |
@vanth0me without any code sample or logs its not possible to find the cause of the issue.
Are there any logs that you can share? |
I can't share the app I'm currently working on, but I can share a private project where it just happend. I think it is on BitBucket, is there an easy way to share this with you? Edit: checked my logcat but didn't really find anything with flutter or the app name. There is so much spam in there and knowing the time it happend is basically impossible. |
This comment has been minimized.
This comment has been minimized.
Huawei Mate30 Pro, I have encountered this problem many times |
@liwangyong @zhangruiyu can you guys please share a reproducible steps along with the output of |
@vanth0me I tried running your project and it fails to build it, looks like there are some compile-time errors could you please recheck and also provide the steps to reproduce the issue? Thanks |
@maheshmnj I fixed it, looked like it was a really early version for some reason. The steps are open the app, I don't know if logging in helps but then just switch to another app, wait some time and hope it gives a black screen. The difficulty is finding the balance between opening too soon and the app being killed. There is sadly no guarantee it will happen. |
@vanth0me there is a build time error now the
And if you still face the issue please provide the emulator details on which the issue reproduces as the above devices are not available for me to test. build failure logs
Please make the final changes and make sure the app runs. Thanks. |
I'm sorry, should have mentioned that building is with the no null sound safety option, because of the package. I'm pretty sure the last time it happend on an emulator it was an Android 12 x86_64 (Google APIs) based on a Pixel 5. |
@vanth0me I ran your app and it did not go past the login screen because of the Google sign-in error (probably due to missing app signature) I kept it in the background for around 15-20 mins did not see the black screen when switching back to app. |
Hmm interesting, maybe the app does something self to mimic this behavior. I can also reproduce this issue with launching a release app on my phone, locking the screen and unlocking it. Guaranteed black screen. Nice find from #94921 OP Edit: Forgot your last alinea. It is indeed not just in the debugger. |
I added some comments about what I think is going on here: https://github.com/flutter/engine/pull/30590/files#r783307849 I unfortunately have not been able to reproduce this locally but it should be fixable. |
@dnfield Have you tried to reproduce this with the steps I posted at #93276 (comment)? Judging by other responses, it seems easy to reproduce this way. |
Trying your method with an installed app didn't create any black screens if the app is idle. It is however very ease to do during boot if the app is changing screens. |
flutter/engine#30590 has landed as fab1982. Once that's finished on CI, you might be able to just update your I found a OnePlus phone but still can't seem to reproduce this myself. |
(It's still building on CI but should be done within the next hour) |
The black screen is still occurring for me. |
What would help at this point is a reproduction that happens consistently, or at least that happens with higher frequency on a greater number of devices. |
@dnfield one easy way to do this is have an app where the launch takes a few seconds, for example with auto login. Quickly open that app, lock your screen and unlock it. Had more luck yesterday with a 80% success ratio, now it's about 30%. At least it's pretty fast to do. |
I was able to reproduce this Issue and I did some investigation on it. Normally, after we open the flutter app and turn off the screen, But on my OnePlus phone, when I turn off the screen, first The following are some logs, the operation of them are the same. Turn off the screen after the App is running, and then turn on the screen. Other Phones
OnePlus display correctly
OnePlus display black screenblack screen case 1
black screen case 2
The detail log at the time was not recorded. Since AFAICS, if flutter doctor -v
```
[✓] Flutter (Channel stable/v2.5.3.xianyu, 2.5.4-0.0.pre.25, on macOS 11.5.2 20G95 darwin-x64, locale zh-Hans-CN)
• Flutter version 2.5.4-0.0.pre.25
• Framework revision 59bd29558b (3 weeks ago), 2021-12-24 19:11:50 +0800
• Engine revision f16240bafd
• Dart version 2.14.4
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.1) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] IntelliJ IDEA Community Edition (version 2017.3.3) [✓] VS Code (version 1.63.2) [!] Proxy Configuration [✓] Connected device (3 available)
|
Sounds like we need to check if surface changed got called without a surface created and if so, insert creation. This is almost certainly a vendor bug though. |
Here I have encountered two situations. The first is that only |
I see. Is the |
Another thing to look at: if we implemented https://developer.android.com/reference/android/view/SurfaceHolder.Callback2 instead, do we get |
According to the log, Usually, when the
It seemed that the OnePlus phone forced the window in visible state when the I found a way to fix this: Please let me know if you guys have any thoughts on this? |
I'd say not. Almost every major brand has issues with this. Xiaomi, Samsung, huawei, pixel, iPhones, and probably more. @ColdPaleLight if I have the time I'll try it tomorrow. |
@vanth0me @RaymondBakker @davidmartos96 |
@ColdPaleLight The code that @AlexV525 posted at #94921 (comment) fixes the issue for me. It also gets rid of the occasional black flickering when turning the screen back on. |
Did not fix it for me for the black screen bug when the app has been in de background. Was unable to reproduce the blacksreen launching the app and locking/unlocking the phone. Could also be me being unlucky, but who knows. |
I have not been able to reproduce this on a Pixel (including two or three different Pixel phones I've tried). If this bug exists on iPhone it is definitely a different bug in different code. We'd need a reproduction for that as well. |
A lot of colleagues of mine use a Pixel and that's how know about the iPhone users as well. From what I have heard iPhone users usually get a black screen after a pop or push. I only had that a few times on Android. It's pretty random and requires the app was in the background for some time. |
@vanth0me it would be helpful if you could provide a minimal reproduction that results in a black screen as you're discussing. |
@dnfield That's the hard part, it's random. It happens just the same as I have described earlier. Have an app with state (I also got it to work with the gallery example shine store app)(Having state makes it seem easier to trigger), put in in the background, wait some time and open the app. I really have not found anything else that creates it that has not been discussed here already. |
Hi, @vanth0me |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of |
Steps to Reproduce
It seems to happen on different Flutter apps. Open a Flutter app, go to your home screen and open some other apps. Wait for some time and open the Flutter app again. There is now a chance that the app shows a black screen. No Appbar, BottomBar or any widget. It happens pretty frequently if you know how to trigger it.
The app seems to respond to user interaction, just had it on the debugger but there is no useful information, no errors, no exceptions thrown. Moving to the android recents screen and returning to the app fixes this. I haven't tried to do this with iOS.
Was able to reproduce this on some older installed apps, app created with Flutter stable 2.5.3 and the latest beta build (2.7.0 iirc).
I can't really create an app sample because it is pretty hard to know when it exactly happens because it is not guaranteed to happen. It does occur on multiple devices and some users have noticed it too. No data on crashlytics or runguarded zone.
The text was updated successfully, but these errors were encountered: