Auto close chrome custom tab
This problem can exist in Xamarin too and the answer applies to issue when using Xamarin.Forms. It can be applied by modifying the Activity attribute. Modify the code to match LaunchMode = LaunchMode.SingleTask
Here is a modified example of Xamarain.Auth from https://developer.xamarin.com/samples/xamarin-forms/WebServices/OAuthNativeFlow/
namespace OAuthNativeFlow.Droid
{
[Activity(Label = "CustomUrlSchemeInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTask)]
[IntentFilter(
new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataSchemes = new[] { "<insert custom URL here>" },
DataPath = "/oauth2redirect")]
public class CustomUrlSchemeInterceptorActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Convert Android.Net.Url to Uri
var uri = new Uri(Intent.Data.ToString());
// Load redirectUrl page
AuthenticationState.Authenticator.OnPageLoading(uri);
Finish();
}
}
}
I also faced the same issue, but in my case its now working.
I launched the custom tab with FLAG_ACTIVITY_NO_HISTORY and FLAG_ACTIVITY_CLEAR_TOP.
customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
And launchMode of my activity was "singleTop".
<activity
android:name=".SomeActivity"
android:theme="@style/SomeTheme"
android:configChanges="keyboardHidden|orientation|screenSize"
android:noHistory="true"
android:launchMode="singleTop" >
<intent-filter>
<data android:scheme="intent" />
<data android:scheme="myFile" />
<data android:scheme="myScheme" />
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
</intent-filter>
</activity>
An important update by @bkant:
I was able to get this to work by changing the launch mode from 'singleTop' to either 'singleTask' or 'singleInstance'. In this mode, the redirect will come to the same Activity via 'onNewIntent'.