nativescript-inappbrowser icon indicating copy to clipboard operation
nativescript-inappbrowser copied to clipboard

Browser screen is closed on android when application launched from background

Open harishchopra86 opened this issue 4 years ago • 9 comments

Which platform(s) does your issue occur on?

  • Android
  • Android version: 9
  • Both emulator and android phone

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

  • CLI: 7.1.2
  • Cross-platform modules: 7.1.0
  • Runtime(s): tns-android: 7.0.1
  • Plugin(s): 3.0.2

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

harishchopra86 avatar Feb 08 '21 16:02 harishchopra86

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

jdnichollsc avatar Feb 08 '21 16:02 jdnichollsc

@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.

harishchopra86 avatar Feb 08 '21 17:02 harishchopra86

That Unhandled Promise rejection is not related to this library

jdnichollsc avatar Feb 08 '21 18:02 jdnichollsc

@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.

harishchopra86 avatar Feb 08 '21 18:02 harishchopra86

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

jdnichollsc avatar Feb 08 '21 18:02 jdnichollsc

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 avatar Feb 08 '21 19:02 harishchopra86

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.

harishchopra86 avatar Feb 10 '21 16:02 harishchopra86

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

jdnichollsc avatar Feb 10 '21 17:02 jdnichollsc

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

jdnichollsc avatar Jul 14 '21 15:07 jdnichollsc