I'm building a video calling app and need to display an incoming call screen. I use a Notification that displays an activity with fullscreen intent mechanism as follows:
private fun createIncomingCallNotification(): Notification {
val fullscreenPendingIntent = IncomingCallActivity.intent() // from splitties.intents module
.toPendingActivity(flags =
PendingIntent.FLAG_UPDATE_CURRENT or
Intent.FLAG_ACTIVITY_CLEAR_TASK or
Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_NO_HISTORY or
Intent.FLAG_ACTIVITY_CLEAR_TOP
)
return NotificationCompat.Builder(this, INCOMING_CALL_NOTIFICATION_CHANNEL_ID)
.setSmallIcon(R.drawable.ic_baseline_call_24)
.setContentTitle("Incoming call")
.setContentText("(919) 555-1234")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_CALL)
.setFullScreenIntent(fullscreenPendingIntent, true)
.setContentIntent(
VideoCallActivity.intent()
.toPendingActivity(flags =
Intent.FLAG_ACTIVITY_CLEAR_TASK or
Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_NO_HISTORY or
Intent.FLAG_ACTIVITY_NO_HISTORY or
Intent.FLAG_ACTIVITY_CLEAR_TOP
)
)
.setAutoCancel(true)
.setVibrate(DEFAULT_VIBRATE_PATTERN)
.setSound(incomingCallSound)
.build()
}
It is used as a notification for a foreground service which is triggered when the receiver receives an incoming call request.
The fullscreen activity and notification display OK. However, when I accept the call by clicking on the notification, fullscreen activity remains in the history stack (even with all these flags added plus the autoCancel). So then, when I end my call the fullscreen IncomingCallActivity pops up. It remains even when I stop the foreground service associated with the notification.
Any help would be appreciated!
TL;DR:
I'm looking for a auto-cancel-like behavior for a fullScreenIntent accompaniying an annotation. As it's for the system to decide whether the activity is shown, I'd like to have a generic approach to cancel the notification and close the fullscreen activity on any action selection (reject or accept the call). I suspect it should be done with a BroadcastReceiver, but looking for tips on how it should be done in a concise manner.
EDIT:
I've managed to solve this with BroadcastReceiver registered within the fullscreen activity with a IntentFilter. In the notification reject action I just sendBroadcast which then finishes the fullscreen activity.
However still looking for a 'best practices' approach on that.