如果我的应用程序具有
A -> B -> C -> D
在堆栈中。如何从Notification中打开活动并使堆栈变为
A -> B -> C -> D -> E
如果应用程序终止了,我该如何从通知中打开应用程序,例如从通知中打开E活动,但又再次打开应用程序时阻止它启动[例如,我打开E活动然后回压以退出应用程序,然后再打开再次申请,我希望它打开A活动(Root Activity)而不是E活动。]
// When Open Application if app is terminated.
val intent = Intent(activity!!, SampleActivity::class.java)
val pendingIntent= PendingIntent.getActivity(activity!!, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
with(NotificationManagerCompat.from(activity!!)) {
notify(
java.lang.System.currentTimeMillis().toInt(), notiBuilder
.setContentTitle("Title")
.setContentIntent(pendingIntent)
.setContentText("body")
.setNumber(1)
.setSmallIcon(R.drawable.notification_icon_background)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.build())
}
// When Open Application if app is not terminated.
val intent = Intent(activity!!, HomeActivity::class.java)
intent.putExtra("FurtherActivity", 1)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
val pendingIntent= PendingIntent.getActivity(activity!!, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
with(NotificationManagerCompat.from(activity!!)) {
notify(
java.lang.System.currentTimeMillis().toInt(), notiBuilder
.setContentTitle("Title")
.setContentIntent(pendingIntent)
.setContentText("body")
.setNumber(1)
.setSmallIcon(R.drawable.notification_icon_background)
.setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
.build())
}
// HomeActivity
override fun onCreate() {
......
......
......
if(intent.getIntExtra("FurtherActivity", 0) == 1) {
SampleActivity.start(this@HomeActivity)
viewpager.currentItem = 0
tab_layout.getTabAt(0)!!.select()
}
......
......
}
override fun onNewIntent(newIntent: Intent?) {
super.onNewIntent(Intent())
if(intent.getIntExtra("FurtherActivity", 0) == 1) {
SampleActivity.start(this@HomeActivity)
viewpager.currentItem = 0
tab_layout.getTabAt(0)!!.select()
}
}
答案 0 :(得分:0)
您可以创建一个处理意图结果的活动,并将该结果根据要求传递给特定的活动 然后只需将HandleIntent活动传递给通知意图,并以ActivityName作为参数来打开特定活动即可。