GoogleChrome / android-browser-helper

The Android Browser Helper library helps developers use Custom Tabs and Trusted Web Activities on top of the AndroidX browser support library.
Apache License 2.0
694 stars 288 forks source link

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

Open Zyxer22 opened 1 year ago

Zyxer22 commented 1 year ago

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):

WilsonAtWork commented 1 year ago

Any updates on this?

Timebutt commented 1 year ago

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?

Zyxer22 commented 1 year ago

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.

fabiel-leon-autofact commented 6 months ago

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