Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

From Notification: AlertDialog without UI

I'm creating a notification which fires an Intent. Here a really shortened excerpt of my code...

Notification notification = new Notification(R.drawable.icon, "notification", System.currentTimeMillis());
NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(BackgroundService.this, ConnectionHandler.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
notificationIntent.addFlags(Intent.FLAG_FROM_BACKGROUND);

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, getString(R.string.notification_title), getString(R.string.notification_body), pendingIntent);
notification.flags |= notification.FLAG_AUTO_CANCEL;
nm.notify(1, notification);

In my intent (ConnectionHandler.class), I'd like to show an AlertDialog, which works. But I'd like the AlertDialog to show up without opening a new UI-Window. The best for me was if the AlertDialog simply appears without anything else when tapping the notification-entry.

Any idea is appreciated.

Regards, Tobi

like image 643
Atmocreations Avatar asked May 16 '11 21:05

Atmocreations


2 Answers

From the Dev Guide:

Showing a Dialog

A dialog is always created and displayed as a part of an Activity.

The easy alternative is to create a very basic Activity, with nothing showing up except the dialog, and calling finish() as soon as the dialog is dismissed.

like image 92
Aleadam Avatar answered Nov 20 '22 05:11

Aleadam


Create transparent Activity like below:

How do I create a transparent Activity on Android?

and combine it with dialog theme.

like image 30
pawelzieba Avatar answered Nov 20 '22 06:11

pawelzieba