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

Fatal Exception occured due to "not attached to window" on AndroidP #384

Open
hhhhub000 opened this issue Dec 27, 2018 · 3 comments · May be fixed by #1018
Open

Fatal Exception occured due to "not attached to window" on AndroidP #384

hhhhub000 opened this issue Dec 27, 2018 · 3 comments · May be fixed by #1018

Comments

@hhhhub000
Copy link

Steps to reproduce:

  1. Open InAppBrowser on cordova app.
  2. Move to Settings.
  3. Setting > Display > Display size. Then change display size.
  4. Resume cordova app.
    Then, App is crashed by fatal exception.
Process: com.myapp, PID: 18768
java.lang.IllegalArgumentException: View=DecorView@fb121f3[MainActivity] not attached to window manager
    at android.view.WindowManagerGlobal.findViewLocked(WindowManagerGlobal.java:497)
    at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:406)
    at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:138)
    at android.app.Dialog.dismissDialog(Dialog.java:375)
    at android.app.Dialog.dismiss(Dialog.java:358)
    at org.apache.cordova.inappbrowser.InAppBrowser$5$1.onPageFinished(Unknown Source:18)
    at xf.c(SourceFile:251)
    at afs.handleMessage(SourceFile:72)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6813)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:522)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:889)

I think MainActivity have been destroyed and dialog is detacched when Display size is changed.
But InAppBrowser still have old dialog and try to dismiss() when app is resumed.
my-app\plugins\cordova-plugin-inappbrowser\src\android\InAppBrowser.java

    public void closeDialog() {
        this.cordova.getActivity().runOnUiThread(new Runnable() {
            @Override
            public void run() {
                final WebView childView = inAppWebView;
                // The JS protects against multiple calls, so this should happen only when
                // closeDialog() is called by other native code.
                if (childView == null) {
                    return;
                }

                childView.setWebViewClient(new WebViewClient() {
                    // NB: wait for about:blank before dismissing
                    public void onPageFinished(WebView view, String url) {
                        if (dialog != null) {
                            dialog.dismiss();       //!!!dialog is not attached to window
                            dialog = null;
                        }
                    }
                });

This issue is not reproduced on Android O.
(onPageFinished is not called on Android O, So dialog.dismiss() is not called.)

@lizqjue
Copy link

lizqjue commented Jan 10, 2019

This is also happening in Android O, I can confirm it. At least in inappbrowser version 1.3.1

Best regards

@camilaazuma
Copy link

Hi, has anyone solved this one?

@ozgeekemen
Copy link

ozgeekemen commented Apr 16, 2020

When I change this

childView.setWebViewClient(new WebViewClient() {
 // NB: wait for about:blank before dismissing
         public void onPageFinished(WebView view, String url) {
               if (dialog != null && !cordova.getActivity().isFinishing()) {
                    dialog.dismiss();
                    dialog = null;
                }
          }
});
// NB: From SDK 19: "If you call methods on WebView from any thread
// other than your app's UI thread, it can cause unexpected results."
// http://developer.android.com/guide/webapps/migrating.html#Threads
childView.loadUrl("about:blank");

to this

if (dialog != null && !cordova.getActivity().isFinishing()) {
      dialog.dismiss();
      dialog = null;
}

error is disappearing. So loading "about:blank" is it necessary here ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants