I have the following problem. I have an app that receives push notifications from firebase. So far excellent.
When I receive the notification, what I do is create a notification in the following way:
private fun sendNotification(messageBody: String, title: String) {
val intent = Intent(this, NotificacionesActivity::class.java)
intent.setClassName(this.packageName, "${this.packageName}.NotificacionesActivity")
intent.putExtra("notificacion",true)
intent.action = Intent.ACTION_VIEW
intent.addCategory(Intent.CATEGORY_INFO)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED
//intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
val pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT)
//val channelId:Int = getString(R.string.default_notification_channel_id)
val defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)
val notificationBuilder = NotificationCompat.Builder(this, ""/*, channelId*/)
.setSmallIcon(R.drawable.ic_mail)
.setContentTitle(""+title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
notificationManager.notify(0 /* ID of notification */, notificationBuilder.build())
}
Two interesting things happen here:
If the application is in the foreground and I open the notification from the notification manager, the activity I require is opened perfectly.
If the application is in the background and I open the notification from the notification manager, the Login activity that is declared as launcher in the manifest opens.
What I require is that the first option always happens is to say that the ActivityActivity activity is opened even if the app is running in the background.
Is this possible? I will be forgetting some property of the notifications and for that reason I do not obtain the expected result in both scenarios?
Thank you in advance.
Greetings.