Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8464111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:38:32+00:00 2026-06-10T14:38:32+00:00

I am trying to get the internet connectivity state using BroadcastReceiver in my app.

  • 0

I am trying to get the internet connectivity state using BroadcastReceiver in my app. If there is no internet available, I want to show an AlertDialog box.

Here is my BroadcastReceiver:

   public class ConnectivityChangedReceiver extends BroadcastReceiver{

  @Override
  public void onReceive( Context context, Intent intent )
  {
    ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService( Context.CONNECTIVITY_SERVICE );
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
    if (networkInfo != null && networkInfo.isConnected()) {
    } else {
        showInternetAlertDialog(context);
    }
  }

  public void showInternetAlertDialog(Context context){
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setMessage("You have no internet connection.")
                    .setPositiveButton("Retry", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        }
                    });
        builder.show();
        return;
    }    
 }

I have defined this receiver in my manifest too . I have defined the permission for accessing network state in manifest.

    <receiver android:name="com.lisnx.service.ConnectivityChangedReceiver"
        android:label="NetworkConnection">
        <intent-filter>
            <action android:name="android.net.conn.CONNECTIVITY_CHANGE"/>
        </intent-filter>
    </receiver>

But when internet is gone and AlertDialog box tries to open, I get the following exception :

  10-19 16:25:21.474 E/AndroidRuntime( 6864): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application

  10-19 16:25:21.474 E/AndroidRuntime( 6864):     at android.view.ViewRoot.setView(ViewRoot.java:509)

  10-19 16:25:21.474 E/AndroidRuntime( 6864):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:177)

  10-19 16:25:21.474 E/AndroidRuntime( 6864):     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)

  10-19 16:25:21.474 E/AndroidRuntime( 6864):     at android.app.Dialog.show(Dialog.java:241)

I think its an issue of Context but I can’t find out what exactly is the problem. Please help me on this. Any solutions will be appreciated. Thanx in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T14:38:33+00:00Added an answer on June 10, 2026 at 2:38 pm

    That is not possible to display AlertDialog from BroadCast Receiver.

    You have to start some activity from BroadCast Receiver and in that activity you have to display AlertDialog.

    You can set Dialog theme to activity or you can provide transparent layout to that activity.

    Edit :

    Make sure that you start new activity with FLAG_ACTIVITY_NEW_TASK intent flag.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get images from Internet. (i can't show my code here)
How can I get source code off the internet using SVN? I'm trying to
I want to create an app that uses the internet and I'm trying to
Ok so I am trying to get this app to show network error alert
Im trying to get a form working in Internet Explorer. I see that when
I'm trying to get an image off the internet from an URL in java.
I am trying get all html links within a string and replace them using
I am trying get all html links within a string and replace them using
I am trying get Struts 2 and Tiles to work and I am using
I've been trying to get the name/title of internet radio stations based on the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.