我试图启动活动的 A 从通知按钮(用PendingIntent)。当我点击这个通知键和 A 在历史堆栈的顶部,它只是不正确的行为:
什么是应该做的:
活动的 A 必须复制在historystack,这种方式: 在当前活动的 A 是历史堆栈的顶部 之前: [A,...老活动...] 后: [A,A,...老活动...] 在当前活动的 A 不历史堆栈的顶部(默认行为) 之前: [B,......老活动...] 后: [A,B,......老活动...]会发生什么:
的onCreate
被调用,但 getIntent()。getExtras()
是空
。
活动的 A 被替换,而不是重新创建(我要重复的)。
我已经尝试了很多东西: Intent.FLAG *
和 PendingIntent.FLAG *
也不过失败。
修改1: 我想这些常量:
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
(但我没有想清楚前)
code(部分):
意图intentCancel =新的意向书(getApplicationContext(),ChallengeProposalActivity.class);
//intent.setAction(将String.valueOf(System.currentTimeMillis的()));
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(ChallengeProposal.NAME,建议);
PendingIntent pendingIntent = PendingIntent.getActivity(此,0,intentCancel,0);
code(满): http://pastebin.com/vNuEkBvi
我应该怎么办?
相关问题:
PendingIntent不工作中添加额外的意图时
Duplicate MainActivity当从通知
输入 解决方案您已经创建 intentCancel
对象,而是试图把多余的意图
目标:
意图intentCancel =新意图...
intent.putExtra ...
I am trying to start an Activity A from a Notification Button (using PendingIntent). When I tap on this Notification Button and A is on top of history stack, it just not behave correctly:
What it should do:
Activity A must duplicated on historystack, this way: When activity A is on top of history stack Before: [ A, ... old activities ... ] After: [ A, A, ... old activities ... ] When activity A is not on top of history stack (default behavior) Before: [ B, ... old activities ... ] After: [ A, B, ... old activities ... ]
What happens:
onCreate
is called, but getIntent().getExtras()
is null
.
Activity A is replaced and not recreated (I want a duplicate).
I've tried a lot of things: Intent.FLAG*
and PendingIntent.FLAG*
also, but unsuccessfully.
Edit 1: I tried these constants:
Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK
Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP
(but I don't want to clear top)
Code (part):
Intent intentCancel = new Intent(getApplicationContext(), ChallengeProposalActivity.class);
//intent.setAction(String.valueOf(System.currentTimeMillis()));
//intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra(ChallengeProposal.NAME, proposal);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intentCancel, 0);
Code (full): http://pastebin.com/vNuEkBvi
What should I do?
Related questions:
PendingIntent not working when adding extras in intent
Duplicate MainActivity When Enter From Notification
解决方案You have created intentCancel
object, but tried to put extra in intent
object:
Intent intentCancel = new Intent...
intent.putExtra...