How to display a Dialog from a Service

I have read really a lot of posts about this topic, however nothing works for me (or doesn’t have the effect I wish).

I have a an application, that after logging in starts a background Service (implementation of the Service class). This service syncs itself with a Server and if a new order comes, it creates a notification.

  • Why it is not possible to play an audio file on a voice call in android
  • Android Layout align bottom
  • Android Completely transparent Status Bar?
  • How do I discover a Chromecast device using Android?
  • Android device orientation without geomagnetic
  • how can I access Picasso' s cached image to make a share intent?
  • So far, everything works great, I have the notification and the Toast message. However, I would like to have a dialog, that notifies the user about the new order.

    As I understood, you can start an activity from within the service, which displays the dialog. This works, but the activity starts on top of the current activity stack and displays the dialog. I have an activity with no view attached and it correctly displays the dialog, however, on a black background.

    What I want is to display the dialog on the current activity, causing the actual background(the running activity) to fade and display the dialog.

    Is this somehow possible?

    Thank you,

    Related posts:

    Android Spinner databind using array list
    location manager issue for ice cream sandwhich
    java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState:- Error in Fr...
    Difference between setRepeating and setInexactRepeating of AlarmManager
    Implement Firebase inside of a Library
    Android layout previewer throws error when adding custom LinearLayout
  • Android : Top level element is not completed in AndroidManifest.xml
  • Android 2.1 vs 2.2
  • Does Google offer an API that I can use to get the location of my phone?
  • Invalidating 1 Custom View Causes All Custom Views In A View Group To Be Invalidated?
  • On the Kindle Fire, is it possible to get a user's email address?
  • How can I show a Progress dialog between two activities?
  • 5 Solutions collect form web for “How to display a Dialog from a Service”

    I highly, highly, HIGHLY recommend that you DON’T do this (it goes against Android design and UI guidelines). Notifications are the preferred way to accomplish what you are doing (which it sounds as if you have already accomplished).

    That being said, if you must do it, I would recommend just using a Dialog themed activity. That way you don’t have to start up a separate dialog. Please see for how to do this.

    We can show dialog from service only if it is a system alert dialog. So, set TYPE_SYSTEM_ALERT window layout parameter to Dialog as follows:


    But, it needs SYSTEM_ALERT_WINDOW permission. So, don’t forget to add this permissin in Manifest file.

    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    you can start by learning on how to create an activity that looks like a dialog (no title bar, transparent background, “floating” effect, etc.)
    and no, you can’t just start a dialog without an activty

    No, you can’t hijack activity that is not “yours” and command it to show dialog.
    Your approach of starting your own activity is the classic one.

    You cannot show a dialog. But you can go the alernative way by inflating your customized view so that you can show a dialog on the screen whenver certain conditions are met.

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