apache / apache/cordova-plugin-inappbrowser
Fatal Exception occured due to "not attached to window" on AndroidP
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 2.2k
- PR merge metrics
- No merged PRs in 30d
Description
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.)
Contributor guide
Research direction
Start in my-app\plugins\cordova-plugin-inappbrowser\src\android\InAppBrowser.java, focusing on closeDialog() and the onPageFinished callback that calls dialog.dismiss(). Reproduce the Android P display-size change sequence and verify that resuming the app no longer crashes when the old dialog is detached from the window.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, java
- Domain
- mobile-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100