7

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

Henrik P. Hessel
  • 36,243
  • 17
  • 80
  • 100
Atmocreations
  • 9,923
  • 15
  • 67
  • 102

3 Answers3

8

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.

Community
  • 1
  • 1
Aleadam
  • 40,203
  • 9
  • 86
  • 108
  • 1
    You can also give that Activity a translucent theme to keep anything but the dialog from showing up. – Marcus May 16 '11 at 22:25
  • bah that's bad that the dialog is part of an Activity. But `finish()`ing after dismission did the trick. Many thanks! – Atmocreations May 16 '11 at 22:27
5

Create transparent Activity like below:

How do I create a transparent Activity on Android?

and combine it with dialog theme.

Community
  • 1
  • 1
pawelzieba
  • 16,082
  • 3
  • 46
  • 72
0

There's a very easy answer: the Activity CAN look like a dialog. In manifest add this:

android:theme="@android:style/Theme.Dialog"

And it will look like a dialog.

If you want to show up an Alert Dialog, use this code:

  • Activity
    AlertDialog d = new AlertDialog.Builder(this).setTitle("Blah-Blah").setBlah().show()
  • Manifest
    android:theme="@android:style/Theme.Translucent"
Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158
Chaoz
  • 2,119
  • 1
  • 20
  • 39