Transparent activity is opening over main activity. How to open it not over main activity?

I am building an application which will show a notification and on clicking the notification, I want to open a transparent dialog like activity which will have option related to that notification.

I defined a transparent activity and registered it in notification like this.

  • What is the difference between onCreateOptionsMenu(Menu menu) and onPrepareOptionsMenu(Menu menu)?
  • Navigation Drawer Android API specific Layout Attribute
  • Webcam supported picture sizes
  • How to set a radio button in Android
  • ViewPager with multiple fragment instances of same class
  • emulator: WARNING: Could not initialize OpenglES emulation, using software renderer
  •  Intent notificationIntent = new Intent(context, EasyToDoReminder.class);
     PendingIntent contentIntent = PendingIntent
                                    .getActivity(context, 0, notificationIntent, 0);

    The activity starts, but the main activity is statred behind it. How to open the Reminder activity independently?

    And I am not trying to show a dialog. I want to show an activity look like a dialog. I am already using the theme as you mentioned. I have also one main activity. When I am trying to start my transparent dialog like activity, the main activity is getting started then over that the dialog like activity is started.

    Anyone can please suggest to do this in a better approach?

    Related posts:

    How to show the text on a ImageButton?
    How to use build types (debug vs release) to set different styles and app names?
    Register broadcast receiver dynamically does not work - BluetoothDevice.ACTION_FOUND
    A library uses the same package as this project after importing Facebook SDK
    How can I specify per flavor buildType sourceSets?
    How to position StaticLayout in android?
  • Android dalvikvm-heap: Clamp target GC heap
  • Error : Failed to find the bower component “ionic-platform-web-client”
  • Android TaskStackBuilder startActivities opens a white screen and freezes sometimes on Samsung Galaxy S3
  • VPN connection from Android emulator fails
  • How to style the DrawerArrowToggle from Android appcompat v7 21 library
  • Make ImageView fit width of CardView
  • 9 Solutions collect form web for “Transparent activity is opening over main activity. How to open it not over main activity?”

    ok i had this problem too
    use another LAUNCHER activity for second activity

    manifest :

        <activity android:name=".popup.PopUp"
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />

    and in intent :

            Intent i = new Intent();
            i.setClass(service.getBaseContext(), PopUp.class);
            i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                    Intent.FLAG_ACTIVITY_SINGLE_TOP |
            i.putExtra("id", id + "");

    if you call from a service use service.getBaseContext() , and if you not just use your context

    You can’t start your dialog without starting the activity. I think you need to do the following:

    • Create a new activity where you change its style to be a Dialog style:
      • android:theme="@android:style/Theme.Dialog"
    • In this new activity, add all what you want to happen when the user click the notification.
    • Link your notification to it like you did.

    Now, when you click the notification, the dialog will show up.

    Like booger said, Add android:theme="@android:style/ThemeDialog" to <application ... </application> part of your manifest to have your main activty just show as a dialog box, without a background.

    You could also use an alert dialog with buttons in it which could activate the options you want , instead of having a second activity: AlertDialog reference

    You need to call finish(); from your main activity so that it doesn’t re-appear behind every other activity.

    Better explained here Unexpected behavior when launching a dialog-style activity

    I solved my problem.

    First I added the attribute in the matifest file for my 2nd activity like below.


    and while lauching from notification I set the following flag to the intent.

    Intent notificationIntent = new Intent(context, EasyToDoReminder.class);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET );

    It works!!

    Here’s what did the trick for me –

    For the result intent do this:

    public void onReceive(Context context, Intent intent) {

    For the activity encapsulating the dialog alert do this (in the manifest file):


    Hope this helps…

    I don’t think you will be able to start a Dialog without first starting an Activity (which is I think what you are trying to do).

    You could style your main activity to look like a dialog – but otherwise, I think you cannot start a dialog without having an Activity context to tie it to.

    I may be mis-understanding your question.

    You may try Popup window, then inflate your layout inside that Popup window.
    Or, use android:theme=”@android:style/Theme.Dialog” to get the effect of dialog when it’s actually an activity

    Set android:taskAffinity and android:launchMode="singleTask" in your manifest file for your dialog activity. All credits to this answer.

    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.