Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity started from notification opened on top of the activity stack

I have an application with multiple activities. On one of them, I set up an alarm. I press the HOME button. When the alarm is triggered, a notification appears. When clicking on the notification, I start a dialogue-like Activity (@android:style/Theme.Dialog). Although I am on the desktop screen, Android opens my last activity and then shows my dialogue-like activity on top of that. I just want to show my dialogue activity wherever the user is.

Does anyone have an idea of what is wrong?

Intent notificationIntent = new Intent(this, NotificationActivity.class);
notificationIntent.putExtra(Constants.EXTRA_ALERT_MESSAGE, contentText);
PendingIntent contentIntent = PendingIntent.getActivity(this, Constants.PENDING_INTENT_REQ_DIALOG, notificationIntent, 0);
no.contentIntent = contentIntent;
like image 259
Catalin Morosan Avatar asked Jan 07 '11 17:01

Catalin Morosan


1 Answers

You probably want to set android:taskAffinity and android:launchMode="singleTask" in your manifest file for your dialog activity. Setting taskAffinity will cause that Activity to launch in a separate task with its own stack. The singleTask may or may not be completely appropriate for your application but you'll probably want either it or singleInstance depending on your use case. You will need to read the documentation to determine which one will work for you.

like image 178
Rich Schuler Avatar answered Nov 15 '22 12:11

Rich Schuler