asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
Notification 想要点击不触发任何intent:
PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(), 0, null, 0);
Notification 想要点击返回主程序,如果程序已经打开,效果要跟长按home或者点击launcher一样:
Intent intent = new Intent(this, Main.class);
多设置下面2个
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(), 0, intent, 0);
Notification 点击不重复触发activity,只出现单个:
Intent intent = new Intent(this, someactivity.class);
需要设置flags
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(
getApplicationContext(), 0, intent, 0);
   


Ps:

当主Activity设置了lauchMode为singleTask的时候, 每次长按home返回的时候都会返回到主Activity。这并不是我们想要的结果。

This is not a bug. When an existed "singleTask" activity is launching, all other activities above it in the stack will be destroyed.

When you press HOME and launch the activity again, ActivityManger calls an intent{act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flat=FLAG_ACTIVITY_NEW_TASK|FLAG_ACTIVITY_RESET_IF_NEEDED cmp=A}, so the result is A > B > HOME > A.

It's different when A's launchMode is "Standard". The task which contains A will come to the foreground and keep the state the same as before.

You can create a "Standard" activity eg. C as the launcher and startActivity(A) in the onCreate method of C

OR

Just remove the launchMode="singleTask" and set FLAG_ACTIVITY_CLEAR_TOP|FLAG_ACTIVITY_SINGLE_TOP flag whenever call an intent to A


posted on 2011-10-31 16:47 汪杰 阅读(418) 评论(0)  编辑 收藏 引用 所属分类: Java
只有注册用户登录后才能发表评论。

<2024年4月>
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 457612
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜