Aux
Aux

Reputation: 438

How to open dialog styled activity from notification without previous activity closing?

  1. I have an Activity with dialog style so it visually opens on top of previous activity.
  2. I have a notification which opens this activity like this:
Intent intent = new Intent(this, CalcActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE)).notify(0, builder.build());

The problem is that when user taps my notification, previous visible activity closes, home screen appears and my dialog is displayed on top of home screen. How to prevent closing of previous activity? Please note that previous activity might not come from my app.

Upvotes: 2

Views: 541

Answers (1)

Priyanka C
Priyanka C

Reputation: 300

Use Intent as below :

Intent intent = new Intent(this,MainActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

and in AndroidManifest.xml register activity and use theme as dialog:

<activity android:name=".MainActivity" android:theme="@style/Theme.AppCompat.Light.Dialog"/>

Upvotes: 0

Related Questions