PendingIntent不会重新创建活动(含附加)时,它已经在历史堆栈顶部 [英] PendingIntent not recreating activity (with Extras) when it is already on history stack top
问题描述
我试图启动活动的 A 从通知按钮(用PendingIntent)。当我点击这个通知键和 A 在历史堆栈的顶部,它只是不正确的行为:
什么是应该做的:
- 活动的 A 必须复制在historystack,这种方式:
- 在当前活动的 A 是历史堆栈的顶部
之前:
[A,...老活动...]
后:
[A,A,...老活动...] - 在当前活动的 A 不历史堆栈的顶部(默认行为)
之前:
[B,......老活动...]
后:
[A,B,......老活动...]
- 在当前活动的 A 是历史堆栈的顶部
会发生什么:
-
的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
我应该怎么办?
相关问题:
<一个href="http://stackoverflow.com/questions/24766035/pendingintent-not-working-when-adding-extras-in-intent">PendingIntent不工作中添加额外的意图时
<一个href="http://stackoverflow.com/questions/11606809/duplicate-mainactivity-when-enter-from-notification">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 ... ]
- When activity A is on top of history stack
What happens:
onCreate
is called, butgetIntent().getExtras()
isnull
.- 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...
这篇关于PendingIntent不会重新创建活动(含附加)时,它已经在历史堆栈顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!