Eman87
Eman87

Reputation: 2745

Android notification to open DialogFragment

I Have a class that extends DialogFragment. I want to make my app do a Notification and when the user selects the notification, opens the DialogFragment with its layout and some data. Is there are any source code to do this?

Hope anyone helps me. Thanks in advance.

Upvotes: 1

Views: 1143

Answers (2)

Techfist
Techfist

Reputation: 4344

To answer, you can't open a dialog via onclick of a notfication, there is no way in android, what you can do is,

to Start activity themed as Dialog

<activity android:theme="@android:style/Theme.Dialog">

now when startActivity() is called, its displayed like dialog, so moove everything you want to display here and call this activity by pending intent.

Also to add further, to make sure your activity wont appear in recent task list you can add the following excludeFromRecents=true

Upvotes: 1

Shailendra Madda
Shailendra Madda

Reputation: 21531

Just make the pendingintent open up one of your activities and have your activity be complete transparent and just open a dialog.

Intent notifyIntent = new Intent(context,YourActivityClassHere.class);
notifyIntent.setFlag(Intent.FLAG_ACTIVITY_NEW_TASK);
//UNIQUE_ID if you expect more than one notification to appear
PendingIntent intent = PendingIntent.getActivity(SimpleNotification.this, UNIQUE_ID, 
            notifyIntent, PendingIntent.FLAG_UPDATE_CURRENT);

Upvotes: 0

Related Questions