Auto chrome closing tab

I got an application that was used to open the phone browser, where the user would be redirected to my webapp, where after a certain user action, webapp redirects back to the application using intent filters

<application> <activity android:name="com.xyz.sdk.SomeActivity" android:allowTaskReparenting="true" android:configChanges="keyboardHidden|orientation|keyboard|screenSize" android:launchMode="singleTask" android:noHistory="true" android:theme="@android:style/Theme.NoTitleBar"> <intent-filter> <data android:scheme="someString-${applicationId}" /> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> </intent-filter> </activity> </application> 

I recently switched to using custom Chrome tabs instead of a browser (Webview is not an option due to security issues)

Unfortunately, when redirecting back to the application in user chrome tabs, the chrome custom tab does not close automatically. Despite the fact that I can check through the logs that the application received a response, the user tab remains open and remains on top, so the user cannot see what is happening in the application until he closes the application.

The workaround I found was to set the NEW_TASK flag when starting my custom tab, but this makes my application and custom tab appear as two separate applications, which is the reason I left browsers first.

In short: I have an application A that opens a user tab, a web application opened on a user tab redirects back to application A using intent filters, but the vustom tab does not close and remains on top until the user panel closes it.

I tried to set the NO_HISTORY flag for custom tab settings, but that didn't make any difference.

custom tab code:

  CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder() .setShowTitle(true) .setToolbarColor(getToolBarColor()) .setStartAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right) .setExitAnimations(this, android.R.anim.slide_in_left, android.R.anim.slide_out_right) .build(); customTabsIntent.intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); customTabsIntent.launchUrl(this, Uri.parse(url)); customTabsIntent.launchUrl(this, Uri.parse(url)); 

UPDATE I realized that if the intent filter redirects back to another application, then the user tab successfully completes (provided that it has singlet activity, and no history is set to true) But in my case we need to redirect back to that the same activity with which the user tabs were called.

+6
source share
1 answer

I also ran into the same problem, but in my case, it now works.

I launched a 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 the 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> 
+2
source

Source: https://habr.com/ru/post/1015365/


All Articles