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

When app is in background, and then other appsareused, switching back to our app fails to display the webview #1923

Closed
2 tasks done
tototo23 opened this issue Dec 18, 2023 · 15 comments
Labels
bug Something isn't working

Comments

@tototo23
Copy link

  • I have read the Getting Started section
  • I have already searched for the same problem

Environment

Technology Version
Flutter version 3.16.4
Plugin version 5.8.0
Android version 14
iOS version
macOS version
Xcode version
Google Chrome version

Device information: Google Pixel 5

Description

Expected behavior: When the app goes in background to use other apps, when going back to foreground, it should display the webview as it was

Current behavior: If I put app background and foreground without other extra action, it works well. If i open others apps and switch back to that app (that is then resumed to foreground), the webview isn't visible anymore/disappeared. It's only a UI issue, because i see in the logs that it keeps getting actions from the user : i can click on buttons etc. I tried everything and the only way i found the to bring back the webview visible are :

  • changeing the key of the webview Widget, but i loose its navigation state, so not a solution
  • click in an input text field, that forces the app sizement to show keyboard and then the webview reappear

Steps to reproduce

Simply using this code :

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

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

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: InAppWebView(
        initialUrlRequest: URLRequest(url: Uri.parse('https://pub.dev/packages/flutter_inappwebview')),
      ),
    );
  }
}
  1. Run it on device, it shows the pub.dev page
    image
  2. Put the app on background (if you put it straight to foreground it's ok)
  3. Run, for example, Facebook, then set in background ;
  4. Run for example instagram ; then set it in background ;
  5. Switch back to main app, via the app switcher -> I have a "black screen" (background of the webview), but in logs i see that it keeps gettings events on the webview. So the webview is still here in some way :
    image

To be sure it's not a low-level webviexw issue I tried with webview_flutter, and that one doesn't have this "disappearing" issue.

I don't see explciit errors in console, except maybe a "E/OpenGLRenderer(16792): Unable to match the desired swap behavior." that seems to occure when the app goes back to foreground (but it also appears when it successuflly goes back to foreground with webview shown...)

@tototo23 tototo23 added the bug Something isn't working label Dec 18, 2023
Copy link

👋 @tototo23

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

@pichillilorenzo
Copy link
Owner

Use latest plugin version 6.
Plugin version 5 will not have other updates.

@tototo23
Copy link
Author

Ok thank you @pichillilorenzo , i'll make the same tests with ^6.0.0-rc.2 :)

@tototo23
Copy link
Author

Thanks again @pichillilorenzo , I tried with the little code I've shown and it fixed my issue, i'll try in my main app. Thank you for that quick answer !

@pichillilorenzo
Copy link
Owner

Ok, version 6 has a lot of changes under the hood 👍

@jenseralmeida
Copy link

jenseralmeida commented Dec 22, 2023

Hi @pichillilorenzo ,

Thanks for sharing a possible working solution so quickly, and I am working to migrate to the ^6.0.0-rc.2 to see if it fixes my app, but I need to share critical information about this issue.

  • My application is working for a few years already using this awesome component
  • Last week we started to get clients complaining about the widget blanking out after doing the exact steps described in this issue
  • We could not reproduce the issue until yesterday I decided to check and install the latest Samsung update One UI 6 + Android 14 from One UI 5 + Android 13, and that was it. I could reproduce the issue consistently, and as already mentioned by @tototo23 , everything appears to be working, except that nothing is showing.

So, the bottom line is that our application is this component rendering our web app + native bindings using js bridge to run native code and integration with external devices, and etc. So, if this component does not work, then the application is useless, and our client operators are unable to use any other workaround.

Upgrading to the v6 can potentially fix this issue, but I just started to struggle with the migration while I'm writing this. So, to be able to release an urgent fix I will need to put a high-risk update in place on a critical part of the application, and some complex integration that needs to keep working.

If v6 works, I will probably not have the time for a v5 fix that would be ideal as it would allow me to release a small and low-risk fix. But, I hope that this message can make you change your mind about fixing the v5, so other users of this component will not have to release a critical fix doing a risky update, as more and more Android devices are upgrading.

@pichillilorenzo
Copy link
Owner

@jenseralmeida I understand the situation but the problem here is that I don’t know what is the cause about that and why it seems to work on v6 and not in v5.
As I said, v6 has a lot of changes on the native code, so it could be fixed by something specific that may require to change all the code behind it.
Unfortunately, I’m not able to manage also the older versions because it requires a lot of time.

If you are able to reproduce the issue consistently, then you could take a little time to update the code to work for v6 and make the same tests to check if it works.

Migrating to v6 should not be difficult: https://inappwebview.dev/docs/migration-guide

Everything is there, just the older methods/settings has been set as deprecated.
Also, v6 contains other fixes that v5 currently doesn’t have and should behave better.

@jenseralmeida
Copy link

jenseralmeida commented Dec 22, 2023

@pichillilorenzo , thank you again for taking the time to answer my message, and I got your point. I have no idea how you manage to maintain such a great product.

I have finished my migration to v6 we are launching the beta version to the affected users while we take time for the proper testing. I ran into the issues below, and I am posting here to help others with the migration.

The migration is easy and quick, but as it is a bigger change between v5 and v6, and because of it we are just being over-cautious on the testing side.

@pichillilorenzo
Copy link
Owner

@jenseralmeida yes, that’s correct, I need to add that there. It was a change made recently because of the plugin conversion in a Federeted plugin and I forgot to add it there, thanks!

v6 should be better in about a lot of things compared to v5.

@pichillilorenzo
Copy link
Owner

Migration guide updated with these tips 👍

@synapticweb
Copy link

synapticweb commented Jan 20, 2024

I had the same issue on a Samsung A52s with Android 14, but not on a Samsung A14 with either Android 13 or Android 14. I have inappwebview 5.8.0.
Seems to be something similar to this. I managed to find a workaround by setting hybrid composition to true (I understand that in 5.x.x it is by default set to false, while in 6.x.x is by default true).

InAppWebView(
         initialOptions: InAppWebViewGroupOptions(
             android: AndroidInAppWebViewOptions(
                      useHybridComposition: true
                    )
                  ),
//other arguments 
)

@pichillilorenzo
Copy link
Owner

@synapticweb the issue is explained here: #1981

@KiraResari
Copy link

I also have the same issue, and can confirm that it can be fixed by setting useHybridComposition: true in the AndroidInAppWebViewOptions. @synapticweb : thanks for sharing this workaround!

@pattkab
Copy link

pattkab commented Apr 6, 2024

It works. Adding hydridComposition for Android options sorted the issue. The webview now persists even when I navigate to other apps and my app is running in the background. Thanks for sharing this workaround @synapticweb

Copy link

github-actions bot commented Oct 4, 2024

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 and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants