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
汪杰 阅读(429)
评论(0) 编辑 收藏 引用 所属分类:
Java