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 6940893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:48:52+00:00 2026-05-27T12:48:52+00:00

I am having a strange issue. I have a very simple piece of code

  • 0

I am having a strange issue. I have a very simple piece of code that is meant to trigger whenever someone connects to a wifi access point.

IntentFilter ConnectedFilter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
getApplicationContext().registerReceiver(ConnectedToAPReceiver, ConnectedFilter);

    private BroadcastReceiver ConnectedToAPReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) 
        {
            final String action = intent.getAction();

            if (action.equals(ConnectivityManager.CONNECTIVITY_ACTION)) 
            {
                ConnectivityManager connManager = (ConnectivityManager)getSystemService(CONNECTIVITY_SERVICE);
                NetworkInfo Wifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
              if (Wifi.isConnected()) 
              {
                      // If we get here, it means that the user has just connected to wifi. 
              }
            }
        }
};

This code works very well for what I need it to do. However I am getting strange occurrence, that when the back, or home button is pressed the broadcast receiver is also triggered. Also, loading up the App triggers this as well.

Does anyone know why pressing these buttons would be viewed by Android as causing a connectivity change? And does anyone have any idea’s how to easily distinguish between these button presses and a valid connectivity change.


This is part of a solution thanks to some work.

Firstly I have two classes, an activity class and a service class. In my activity class, I set a variable in the service class using a broadcast receiver whenever the onPause and the onDestroy are called. (These get triggered when the user presses these buttons). The receiver in the service class picks up this intent and sets the public variable.

Then in the activity classes onResume I check this variable, and send another intent to the service to reset the variable to it’s default state. Here I also set a local flag. When I’m doing any processing I simply check that flag beforehand and handle it appropriately.

  • 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-05-27T12:48:52+00:00Added an answer on May 27, 2026 at 12:48 pm

    I can confirm that behavior in apps of mine as well. I dont believe it is the act of pressing back or home that is really causing this, rather that whatever is now being resumed as a result of the back or home (widgets in the home case, I suppose) happens to use a network connection, requested or started using a connection and that has the affect of triggering your Broadcast receiver.

    If you didnt want to respond to these false positives, you could do a bit more processing of the Intent your BroadcastReceiver gets and possibly keep track of the wifi connection state within your receiver so you dont take some action when you get another CONNECTIVITY_ACTION but know that wifi is already connected.

    The documentation around some of these arent super clear but here are some additional things you can inspect about the intent that might help you decide whether or not you need to do something:

    // true when there is no connectivity whatsoever
    boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
    
    // lots of extra info & detailed state about the connection
    // see http://developer.android.com/reference/android/net/NetworkInfo.html   
    NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
    
    NetworkInfo otherNetworkInfo = (NetworkInfo)intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
    
    String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
    boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a very strange issue regarding postback in ASP.NET. I have page dynamically populating
I'm having a strange issue here, i have this bit of code: <?php if
I'm having a strange issue that I've never encountered before. I have a partial
I'm having a strange issue that I think I have a workaround for, but
I am having a strange issue, I have a new asynctask launced whenever i
I have a very strange issue that only affects webkit browsers for some reason,
Having a strange issue with some C# code - the Getter method for a
I am having a strange issue that I can't seem to resolve. Here is
I'm having a very strange issue with Python's subprocess.Popen. I'm using it to call
I'm having a strange problem here... I have an ASP.NET 3.5 application that has

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.