proyecto26 / nativescript-inappbrowser

📱InAppBrowser for NativeScript (Android & iOS) 🤘
https://market.nativescript.org/plugins/nativescript-inappbrowser
MIT License
76 stars 21 forks source link

Browser screen is closed on android when application launched from background #60

Open harishchopra86 opened 3 years ago

harishchopra86 commented 3 years ago

Which platform(s) does your issue occur on?

Please, provide the following version numbers that your issue occurs with:

Please, tell us how to recreate the issue in as much detail as possible.

I am using the plugin for opening a login url inside the application where user have to enter his credentials. During that process if user closes the application by pressing home button on android phone, and opens the app again by pressing app icon from phone menu, webview screen is automatically closed. I wanted to know if is there a way to keep the webview login screen open when user opens the app by pressing app icon from phone menu. I am using: android:launchMode="singleTask" in AndroidManifest.xml

Is there any code involved?

It can be reproduced in sample application

jdnichollsc commented 3 years ago

Please check this comment: https://github.com/proyecto26/react-native-inappbrowser/issues/153#issuecomment-727833604 Let me know

harishchopra86 commented 3 years ago

@jdnichollsc Thanks for prompt response.

However it is still the same when application is launched from phone menu launcher icon and I get this error on console when application is launched from launcher icon:

JS: Unhandled Promise rejection: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference ; Zone: <root> ; Task: null ; Value: Error: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources$Theme android.content.Context.getTheme()' on a null object reference createAlertDialog(file: node_modules/@nativescript/core/ui/dialogs/index.android.js:8:0)
JS:     at (file: node_modules/@nativescript/core/ui/dialogs/index.android.js:95:0)
JS:     at ZoneAwarePromise(file: node_modules/@nativescript/zone-js/zone-nativescript.js:902:0)
JS:     at alert(file: node_modules/@nativescript/core/ui/dialogs/index.android.js:92:0)
JS:     at openBrowser(file: src/app/item/item-detail.component.ts:63:24)

Any advise on its fix would be highly appreciated.

Here is my use case:

  1. User clicks login button from app
  2. It opens login flow inside web view
  3. User enter credentials inside web view and presses login.
  4. If credentials are correct, webview opens 2FA text box where user needs to input his 2FA code
  5. User opens google authenticator for 2FA code
  6. Opens app again to enter 2FA code
  7. Here, if app is launched from launcher app icon web view tab is already dismissed so user have to start login flow again from beginning.
jdnichollsc commented 3 years ago

That Unhandled Promise rejection is not related to this library

harishchopra86 commented 3 years ago

@jdnichollsc Thanks for checking, is there a way to prevent browser closing when application is launched from background by pressing app launcher icon? Please advise. Thanks.

jdnichollsc commented 3 years ago

Sorry, honestly I have no idea, but any pull request is welcome! 👍

harishchopra86 commented 3 years ago

I had given it a try already but not able to solve myself so looking for community's help. Struggling with it from last two weeks but can't get any idea to resolve this.

harishchopra86 commented 3 years ago

Adding to above, I looked at ChromeTabsManagerActivity callbacks and found that it's onDestroy callback is called when we open the backgrounded application again by pressing launcher icon and when we open application from recently opened apps nothing is called.

jdnichollsc commented 3 years ago

Good catch, it looks like a normal behavior with Android, the Activities are destroyed when the launch icon is pressed again

jdnichollsc commented 3 years ago

Try this approach and let me know 👍 https://github.com/proyecto26/react-native-inappbrowser/issues/213#issuecomment-878915862