android-browser-helper icon indicating copy to clipboard operation
android-browser-helper copied to clipboard

When a separate activity is launched and finished, the app backgrounds and doesn't return to the twa activity

Open Zyxer22 opened this issue 2 years ago • 4 comments

Describe the bug When a separate activity is launched and finished, the app backgrounds and doesn't return to the twa activity.

To Reproduce

  1. In the manifest file, create an intent to launch an activity
  2. In the related Activity class, override the onCreate() with a call to finish()
  3. Cause that activity to launch
  4. The app is no longer in the foreground

Expected behavior The TWA activity reopens.

Code Snippets What we've done in the meantime is created our own version of the LauncherActivity that launches the TWA Activity during the onRestart() lifecycle.

protected void onRestart() {
        super.onRestart();
        this.launchTwa();
//        if (this.mBrowserWasLaunched) {
//            this.finish();
//        }
    }

Smartphone (please complete the following information):

  • Device: Several, including Pixel 6
  • OS: Several, including 12 and 13
  • Browsers Installed: Chrome
  • android-browser-helper library version: 2.4

Zyxer22 avatar Jun 13 '23 18:06 Zyxer22

Any updates on this?

WilsonAtWork avatar Jun 20 '23 15:06 WilsonAtWork

I'm experiencing the exact same issue in my app right now. I'm using a custom Activity to show a splash screen on app start-up. When it disappears (by calling finish()) the app disappears into the background without bringing back the TWA.

Is there any way of easily applying the fix you have @Zyxer22 to an Android package? I'm a web-developer mostly, and use patch-package to apply patches to third party dependencies in the node ecosystem. How did you go about to apply your fix exactly?

Timebutt avatar Aug 20 '23 19:08 Timebutt

If you look at the LauncherActivity that gets generated, it extends a similarly named one from a package. We decompiled that, grabbed the code, and created our own without the commented out bits I mentioned in the OP. It seemed to work, but we didn't move forward with that as a deployed solution. Maintaining our own 'branch' of this file wasn't something we wanted to do and we weren't sure what the other complications might be for removing the finish() call here. It seems pretty safe, but without more knowledge of how the package worked, it wasn't something we wanted to risk breaking larger parts of the app. If you run with the change, let us know what your experience looks like.

Zyxer22 avatar Aug 21 '23 15:08 Zyxer22

hi, i have this problem when navigating from a trusted domain to another, the app backgrounds and doesn't get fixed with the shared code by @Zyxer22

https://github.com/GoogleChrome/android-browser-helper/assets/166756533/6d849f9c-aba6-4868-8f9c-79b9ba130f29

fabiel-leon-autofact avatar Apr 29 '24 14:04 fabiel-leon-autofact