我能描述我的问题的最佳方式如下:
- 在启动时创建一个通知(使用
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
添加更多的标志组合,但它们都没有解决我的问题... 有什么建议吗?