Flutter app showing black screen in task manager in android physical device

Viewed 1682

I have developed a few apps. But, in all those apps there is a common problem where when I go to the recents section in android it shows a black screen instead of the last state of the app.

Bad state image

When I press the recents button and click on my app it just crashes without any error and I have to reopen the app and it works fine.

All of the above problems don't seem to happen in the debug version of the app, only the release version.

3 Answers

enter image description hereThis happens when disable screen capture disableScreenCapture(). Verify and delete the following code if you use it on MainActivity inside onCreate() method.

getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);

FLAG_SECURE Window flag: treat the content of the window as secure, preventing it from appearing in screenshots or from being viewed on non-secure displays.

It is a price to pay for the security of the application. I hope I've helped.

Hi i had the same issue.

After a little debugging sesión i think i found the issue in Android side. And i have a workaround.

I will report the issue to the flutter team.

The problem i when the MainActivity execute the onResume() callback in a short time and in certain circunstancies the screenshot is not ready to show and the os show a black screen because doesn't have the screenshot ready yet.

To avoid in the middle time i needed to override the onPause() callback into the MainActivity and add a delay into.

I am not recommend this solution in production ( but in the mind time can avoid the issue since the flutter team work in a fix from FlutterActivity )

You can add the override into MainActivity:

//Workaround to avoid error with screenshot in the task manager
override fun onPause() {
    Thread.sleep(100)
    super.onPause()
}

Let me know if this fix worked for you.

Here is the issue reported to the flutter team:

https://github.com/flutter/flutter/issues/66288

Try upgrading your flutter version

Related