What I want is to CustomTWAActivity to not close and keep on running.
I have a MainActivity that starts a TWA (Trusted Web Activity based on CCT protocol). I have extended the TWA Launcher with a Custom Class so that I can override its onNewIntent Method and do some work.
From Main Activity I call the CustomTWAActivity like this:
val intent = Intent(this, CustomTWAActivity::class.java)
val args = call.arguments as String?
if (args != null && args.isNotEmpty()) {
intent.data = Uri.parse(args)
startActivity(intent)
isTWAOpen = true
}
TWA opens up a website that then in turn fire a chrome intent that is received by the CustomTWAActivity. The intent-filter is added inside the Activity in Manifest File like this:
<activity
android:launchMode="singleTask"
android:name=".CustomTWAActivity">
<!-- Edit android:value to change the url opened by the Trusted Web Activity -->
<meta-data
android:name="android.support.customtabs.trusted.DEFAULT_URL"
android:value="https://app.skillclash.com" />
<meta-data
android:name="android.support.customtabs.trusted.ADDITIONAL_TRUSTED_ORIGINS"
android:resource="@array/additional_trusted_origins" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:scheme="https"
android:host="app.skillclash.com" />
</intent-filter>
</activity>
I have added a launchMode of singleTask so that it receives the intent in onNewIntent and a new Activity is not created in the stack.
I receive the new intent inside the CustomTWAActivity's onNewIntent method, the task is done first and then TWA closes on its own. Meaning CustomTWAActivity finished method is called automatically. And the control goes back to MainActivity
This is how onNewIntent is overriden:
class CustomTWAActivity: LauncherActivity() {
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
Log.i("intent in launcher", intent?.dataString?: "no intent data received")
if (intent != null) {
if (intent.action === Intent.ACTION_VIEW) {
val value = intent.dataString
TWAUtils.onNewIntentReceived(value)
}
}
}
}
What I want is to CustomTWAActivity to not close and keep on running.