Android Alert dialog from inside an intent service

I want to display an alert dialog from inside an intent service.

   AlertDialog alertDialog = new AlertDialog.Builder(this).create();

This throws the following exception

  • TextView cuts off text when it is long enough
  • Xamarin Visual Studio IOS Development Without a Mac?
  • How do I format a double using Android view data bindings?
  • ActionBarActivity cannot resolve a symbol
  • Why my StringRequest is going always at onErrorResponse method?
  • how to url encode in android?
  •    Unable to add window — token null is not for an application

    I have tried IntentService.this and getApplicationContext() as well. Between i dont want to do it using an activity. I just want to show a simple alert dialog with a little text.

  • Heterogeneous GridLayout
  • Only using Proguard: Could not init DaoConfig => ArrayIndexOutOfBoundsException
  • How to prevent calling onCreateView when back button pressed in fragment in android
  • Android Custom font Spannable Typeface Span
  • Android Client Server communication
  • PreferenceActivity: save value as integer
  • 4 Solutions collect form web for “Android Alert dialog from inside an intent service”

    Need Activity for display AlertDialog, because we can’t display Dialog from any Service


    Create Activity as Dialog Theme and start that Activity from Service.

    Just need to register you Activity in menifest.xml like as below




    public class MyDialog extends Activity {
        public void onCreate(Bundle savedInstanceState) {
            final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setTitle("your title");
            alertDialog.setMessage("your message");

    Only if you set your alertDialog type to TYPE_SYSTEM_ALERT it will be displayed from an intent service.

     AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    add these after your code:


    But, it have a cost:

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

    Please visit

    it will surly help you!!

    or what you can do is register anActivity in menifest.xml as follows




    and work around it

    The problem is because of Context. You can’t use this as Context in Intent Service. So need to pass a Context variable of your Intent Service to your Alert Dialog. Like,

    AlertDialog alertDialog = new AlertDialog.Builder(context).create();
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.