【发布时间】:2011-11-28 16:33:16
【问题描述】:
我可以描述我的问题的最佳方式是这样的:
- 在启动时会创建一个通知(带有
BroadcastReceiver)。 - 我的应用程序主活动已打开并按下主页按钮(应用程序仍在后台运行,直到系统关闭它)。
- 我拉下状态栏并按下之前在启动时创建的通知。
- 启动了一些不同于主要活动的活动。
- 我按下后退按钮并显示主要活动。
如何防止最后一步?我想要使用后退按钮回到原来的位置,即主屏幕(带有所有小部件和应用程序图标的桌面)。我的应用程序的主要活动应该在后台运行,为什么用返回按钮调用它?
如果相关,我创建通知的代码如下所示:
public void createNotification(int notifyId, int iconId, String contentTitle, String contentText) {
Intent intent = new Intent(mContext, NewNoteActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra(AgendaNotesAdapter.KEY_ROW_ID, (long)notifyId);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, notifyId, intent, 0);
Notification notification = new Notification(iconId, contentTitle, 0);
notification.setLatestEventInfo(mContext, contentTitle, contentText, contentIntent);
mNotificationManager.notify(notifyId, notification);
我尝试向intent 添加更多标志组合,但它们都没有解决我的问题...建议?
【问题讨论】:
标签: android notifications android-intent back-button android-pendingintent