Custom Tab fails to return to app - android

Unlike the answer to
Chrome Custom Tab does not go back to app
My app works correctly when pressing the x or using the back button. However, when the server redirects the user back to the app inside the custom tab the window does not close. The redirect is a javascript intent to deep link back into the app. If I use a browser and skip the custom tab the redirect works correctly and closes the browser window. I have tried several values for the launchMode and noHistory in the Manifest but it's not making any difference.
Skipping the Chrome tab and going straight to a browser is the only choice. The user experience with Tabs would be much, much better. The behavior seems to change with different Android versions and gets worse with Android 6 and 7. The only error I can find in the unfiltered adb logcat is:
12-28 23:58:50.580 3595-3713/? I/ActivityManager: Displayed com.modolabs.kand28/com.modolabs.kurogo.core.activity.LoginActivity: +117ms
12-28 23:58:50.590 32437-13513/? W/System.err: remove failed: ENOENT (No such file or directory) : /data/user/0/com.android.chrome/files/android_ticl_service_state.bin
This says that ActivityManager has started LoginActivity inside my app as it should but the LoginActivity window is behind the Chrome Custom Tab. If I complete the user action that invokes the redirect and then manually close the tab using the X, then I can get to the app and I see it is doing what it is supposed to do. My app is not getting focus to be put in the foreground on top of the tab.
Anybody else seeing this? Any suggestions?

Related

Android 12 - Opening a https intent causes app to restart activity and then launches browser

I'm seeing a strange behaviour only happening on android 12 devices.
In a Fragment of the app we tap to open a link in the browser like this:
Intent(Intent.ACTION_VIEW, Uri.parse(link)) and then startActivity(intent)
The link is to our own website which has the host verified.
What happens then is the MainActivity is destroyed and restarted and afterwards, the browser opens.
The app is based on a single activity with Fragments and has launchMode=singleTask
Devices running other than android 12 just open the browser and when going back the app is at the last Fragment visited - this is the desired behaviour and what I would expect as well.
A note on this is that the app handles deep links correctly. It also has the autoVerify enabled and the setup for the assetLinks.json is correct - the app open automatically when clicking a link.
My lines of thought is that the changes introduced around deep links and autoVerify must be causing this. If we swap the link for https://www.google.com it doesn't destroy the MainActivity and we can visit the website and go back to the app. Any other link with one of our hosts causes that behaviour.
Curious if anyone has experience the same. We are thinking in opening a webview inside to avoid this as a temporal solution but it wouldn't be ideal to do so.

Clicking on an ad opens a browser, but I cannot go back to the launching activity screen of my Android app

Even though there is a similar case here:
After click AdMob ads, I cannot return to my Android app by back button
the code proposed didn't solve my case. So I am posting this if there's somebody with fresh ideas to solve this.
I have coded an app for Android. Now I am trying to add ads to this app.
I am implementing the ads from Appodeal. When I show an ad type called MREC (which is a square-like banner) on my main activity, if I click
on the ad, it will open a tab in the default browser of the device.
The problem arises when I press the square button on the device (the menu that displays the current running apps): it displays the browser and
also my own app as active. If I select my app, Android wont let my app come to the forefront, instead it shows the device background or the
recently opened browser. It's like the browser has taken over the "identity" of my app.
So, why I cannot return to the activity screen where the ad is located, and from where the click launched a browser tab?
One more thing is that in the sample apps that Appodeal provide, there is no code in onResume, and there isn't any different code from the
Appodeal SDK in the manifest, and yet, the app returns correctly to the main activity after coming from the browser tab. I am also trying to implement Admob ads, and the same effect happens as described in this post.
Solved! I implemented the advice by the User: AngraX from this page:
How can I do that in Android. Activity -> WebBrowser -> Acrivity, but Press Back not see the WebBrowser
where he recommends to add this to the Main Activity declaration in the Manifest file of your App:
android:allowTaskReparenting="true"
android:launchMode="singleTask"
And it works! After the Smaato ad in my App launches a tab in the default web browser of the device, I am now able to return to my Main Activity, no matter if the returning is done in any of these 3 ways:
By pressing back button the necessary number of times to return to the Main Activity screen, no matter if you press back button from your App or from the browser
By clicking the close (X) button on the screen of your App
By pressing the square button of your Android device (Menu Button), and then choosing your App

deep linking into a cordova app from a web browser on android opens app within the same browser window

On Android, if I open the mobile web browser and click on a deep link it opens the app, but doesn't open a new window and opens it within the same browser window.
How can I make it open an app rather than having the cordova web process run within the same window? I don't want to just put in target=_blank and have it spawn another web window, I'd like it to be an app window proper.
If you open the app manager the deep linked app that it opened in the same window will show up as a web page - however if you look at the debugger it will show up as an app proccess.
I faced exactly the same problem, but found the solution. It has nothing to do with Cordova actually.
If you want the intent that is fired to be handled by the instance of the app that is already open you need to change the launch mode of your Android app. If you specify singleTask as the launch mode this will tell Android to fire the intent on the instance of your app that is already launched. By default it will use the default launch mode which will launch a new instance.
In Cordova you can specify it by adding the following line to your config.xml
<preference name="AndroidLaunchMode" value="singleTask"/>

Why doesn't FLAG_ACTIVITY_NO_HISTORY work on device, but works on emulator?

I am trying to integrate with the LinkedIn api within my app. Most of it is working just fine but for 1 issue. This is how it works:
From my apps settings screen, the user clicks on connect to LinkedIn button which brings up the web view where the user has to enter their linkedin credentials. The web view is launched the following way:
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse(liToken.getAuthorizationUrl()));
i.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(i);
The above is actually done via an asynctask class.
After successful auth from linkedin, the web view goes away and the user comes back to my apps settings page. Here the user has 2 options. He can either click on save or can hit the cancel button. Save button saves the settings and then takes them to the main activity, cancel doesn't save anything and then takes them to the main activity.
The problem is, this all works just fine on 4.2.2 emulator, but on a Google LG Nexus4 device running 4.2.2, hitting on either the save or the cancel button brings back the linkedin webview, which is not the desired behavior.
One thing that I wanted to point out was that the emulator uses the default android browser while nexus4 uses chrome? is that the problem here?
Do I need to set some other flag on the intent?
Have you tried cleaning your project and rebuilding? Delete the app from the device and reinstall?

Android - WebView dies on resume

I have Activity with some data displayed in WebView that I load with WebView#loadDataWithBaseURL
Then I have/click menu option that fires android.content.Intent.ACTION_SEND
Choose email from the chooser
Google email comes up (as expected)
Discard email and hit back button
Action with WebView tries to resume
Bang - I get NullPonterException at line 4380 in WebView.java if (mWebViewCore.getSettings().getNeedInitialFocus()) since mWebViewCore is now null
The only place in code where mWebViewCore is nullified is at WebView#destroy - how do I recover from this? Do I need to recreate the browser and load my data all over again, that seems pretty wasteful? I really appreciate good suggestion at this point
Well, I can tell you that I just tested using a WebView with loadDataWithBaseURL(), where the page I loaded had a link. Clicking on the link brings up the Browser application, as expected. BACK button-ing out of the Browser brings back my app with the WebView just fine, no exceptions.
So, either ACTION_SEND/Gmail are somehow special, or there is something more going on with your app.
Can you replicate the problem in a small project that you can post somewhere?

Categories

Resources