Notices: AlertDialog without UI

I create a notification that triggers an intent. Here is a really shortened snippet 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 intention ( ConnectionHandler.class ) I would like to show an AlertDialog that works. But I would like AlertDialog to be displayed without opening a new user interface. Best for me was if AlertDialog just appears without any others when I click on a notification.

Any idea is welcome.

Regards, Toby

+7
source share
3 answers

In the Dev Guide :

Dialogue display

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

An easy alternative is to create a very simple Activity , while nothing is displayed except the dialog, and finish() is called as soon as the dialog is rejected.

+8
source

Create a transparent activity as shown below:

How to create transparent activity on Android?

and combine it with a conversational theme.

+5
source

There is a very simple answer: Activity CAN looks like a dialog. In the manifest add this:

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

And it will look like a dialogue.

If you want to open the Alert dialog box, use this code:

  • Activity
    AlertDialog d = new AlertDialog.Builder(this).setTitle("Blah-Blah").setBlah().show()
  • Manifest
    android:theme="@android:style/Theme.Translucent"
0
source

All Articles