The best way I can describe my problem is like this:
- A notification is created at boot (with a
BroadcastReceiver
).
- My app main activity is opened and the home button is pressed (the app is still running in the background until the system closes it).
- I pull down the status bar and press on the notification previously created at boot.
- Some activity, different from the main one, is started.
- I press the back button and the main activity is displayed.
How can I prevent that last step? What I want with the back button is to go back where I was, which is the home screen (the desktop with all the widgets and app icons). My app's main activity was supposed to be running on the background, why was it called with the back button?
In case it's relevant, my code to create a notification goes like this:
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);
I tried to add a couple of more flags combinations to intent
but neither of them solved my problem... Suggestions?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…