Atmocreations Atmocreations - 2 years ago 90
Android Question

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);

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 (
), 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

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download