I receive a notification about a new message in chat using FCM while the application is closed. When I click on it, I want to open chat activity, but main activity opens.
Clicking on the push notification will open main activity. In it, I can get a type of notification from intent and open another activity:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
processNotification()
}
private fun processNotification() {
val notificationCategory = intent?.extras?.getString("category") ?: return
if (notificationCategory == "new_message") {
startMessagingActivity()
finish()
}
}
This method seems to me dirty and not convenient. Is it possible to specify the activity that will open when you click on the push-notification?
EDIT: Steps to solve:
Add a intent-filter to the activity you want to open:
<activity android:name=".messages.chatroom.ChatRoomActivity"> <intent-filter> <action android:name="*your-action-name*"/> <category android:name="android.intent.category.DEFAULT"/> </intent-filter> </activity>Add 'click_action="your-action-name"' field to your FCM message.
Android will automatically open activity with action same as click_action