Issue
i'm using fcm data only message. I made some Flow to send user to destination fragment as fcm notification clicked
this is my flow
first) when the fcm message received I add pendingIntent that hold informations about destination fragment to notification builder
second) when notification clicked, it sends user to login activity to check whether user in login state or not
third) if user in login state, I send user to the destination fragment with the informations received from notification pendingIntent (MainActivity -> Fragment)
it works at first shot, but later on even though the destination is changed it only sends the user to the first destination fragment.
my log says that the login activity only receive first destination information but, why? please help me
// this is onMessageReceived, adding pendingIntent
private fun addPendingIntent(
builder: NotificationCompat.Builder, pushIdx: Int, data: Map<String, String>) {
val loginIntent = Intent({“LoginActivitys intent filter name”}).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
putExtra("pushType", data["pushType"])
// the pushType indicate destination fragment
// in this log pushType is change as push is change
Log.e("pushType", "${data["pushType"]}")
…
}
val pendingIntent = PendingIntent.getActivity(
applicationContext,
pushIdx,
loginIntent,
PendingIntent.FLAG_MUTABLE
)
builder.setContentIntent(pendingIntent)
}
// this is login activity
if(isLogin) {
val intent = Intent(applicationContext, MainActivity::class.java)
retrieveAndSetExtras(intent)
startActivity(intent)
viewModel.resetLoginState()
this.finish()
}
private fun retrieveAndSetExtras(sendingIntent: Intent) {
// this log always print first pushType
Log.e("LOGIN", "retrieveAndSetExtras(${this.intent.getStringExtra("pushType")})")
this.intent.getStringExtra("pushType")?.let { pushType ->
sendingIntent.putExtra("pushType", pushType)
this.intent.removeExtra("pushType")
…
}
}
Solution
After read the manual carefully, I Found right answer. This was due to the characteristics of Pendinig Intente.
I only changed the Intent extra and wanted the system to recognize it as another PendingIntent . But it doesn't work that way, so I could fix it by adding the PendingIntent.FLAG_UPDATE_CURRENT flag.
// this is onMessageReceived, adding pendingIntent
private fun addPendingIntent(
builder: NotificationCompat.Builder, pushIdx: Int, data: Map<String, String>) {
val loginIntent = Intent({“LoginActivitys intent filter name”}).apply {
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
putExtra("pushType", data["pushType"])
// the pushType indicate destination fragment
// in this log pushType is change as push is change
Log.e("pushType", "${data["pushType"]}")
…
}
val pendingIntent = PendingIntent.getActivity(
applicationContext,
pushIdx,
loginIntent,
PendingIntent.FLAG_MUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
builder.setContentIntent(pendingIntent)
}
저 메뉴얼은 지금당장은 한글을 지원하지 않기 때문에, 한국 사람들에게는 내 블로그가 도움이 될 수도 있습니다.(Since that manual does not support Korean right now, my blog may be helpful for Koreans.) 제 블로그입니다.
Answered By - timothy jeong
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.