0

I have a transparent activity which is used for getting an AlertDialog. This AlertDialog appears anytime my app gets a push notification(foreground or background). But when the AlertDialog appears and if there is an another Activity in the background AlertDialog appears on top of this Activity. I want to see only the AlertDialog when user taps the notification.

Here is the code that shows the AlertDialog when app is foreground

Intent dialogIntent = new Intent(getApplicationContext(), DialogActivity.class);
MainActivity.this.startActivity(dialogIntent);
MainActivity.this.finish();

And when app is background i use PendingIntent

Intent dialogIntent = new Intent(getApplicationContext(), DialogActivity.class);
final PendingIntent resultPendingIntent =
        PendingIntent.getActivity(
                mContext,
                0,
                dialogIntent ,
                PendingIntent.FLAG_CANCEL_CURRENT
        );

Is there a solution for showing only AlertDialog when user taps the notification ? Any help would be appreciated.

Tartar
  • 5,149
  • 16
  • 63
  • 104
  • you can open a pop up using alert dialog box using custom layout. I have a code to show pop up using alert dialog box custom made – Apoorv Mehrotra Dec 28 '16 at 11:05
  • Here is your solution http://stackoverflow.com/a/2700683/6676466 – Vishal Chhodwani Dec 28 '16 at 11:06
  • @ApoorvMehrotra there is no problem with opening a pop up. – Tartar Dec 28 '16 at 11:06
  • What do you want to accomplish? If you are on the home and this activity is opened from the notification - show the transparent activity with the dialog over the home, correct? And if you're in your app or any other app - you want to stop it and show the dialog?! – Seishin Dec 28 '16 at 11:06
  • @Tartar so you want that code ? – Apoorv Mehrotra Dec 28 '16 at 11:07
  • @Seishin i want to see only the transparent activity. – Tartar Dec 28 '16 at 11:08
  • I dont think you guys did read my question properly. I got the pop up already. I want only the pop up to be shown(not any other activity underneath of the pop up) when device gets the notification. – Tartar Dec 28 '16 at 11:12
  • @Tartar, if you app is present, you can finish all the activities in the activity stack, but if another app is present... It will not be possible to do it that easily. – Seishin Dec 28 '16 at 11:18

1 Answers1

0

In the onCreate below the setContentView put this line

getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

SHA
  • 57
  • 4