PendingIntent不会重新创建活动(含附加)时,它已经在历史堆栈顶部 [英] PendingIntent not recreating activity (with Extras) when it is already on history stack top

查看:250
本文介绍了PendingIntent不会重新创建活动(含附加)时,它已经在历史堆栈顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图启动活动的 A 从通知按钮(用PendingIntent)。当我点击这个通知键和 A 在历史堆栈的顶部,它只是不正确的行为:

什么是应该做的:

  • 活动的 A 必须复制在historystack,这种方式:
    1. 在当前活动的 A 历史堆栈的顶部
      之前:
      [A,...老活动...]
      后:
      [A,A,...老活动...]
    2. 在当前活动的 A 历史堆栈的顶部(默认行为)
      之前:
      [B,......老活动...]
      后:
      [A,B,......老活动...]

会发生什么:

  1. 的onCreate 被调用,但 getIntent()。getExtras()
  2. 活动的 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(部分):

 意图int​​entCancel =新的意向书(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 对象,而是试图把多余的意图目标:

 意图int​​entCancel =新意图...
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:

    1. When activity A is on top of history stack
      Before:
      [ A, ... old activities ... ]
      After:
      [ A, A, ... old activities ... ]
    2. When activity A is not on top of history stack (default behavior)
      Before:
      [ B, ... old activities ... ]
      After:
      [ A, B, ... old activities ... ]

What happens:

  1. onCreate is called, but getIntent().getExtras() is null.
  2. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆