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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:34:17+00:00 2026-06-10T12:34:17+00:00

I have a very common problem which I think every android developer faces at

  • 0

I have a very common problem which I think every android developer faces at some time. I am making an app which loads data from web-server. So internet connectivity is being used. But I have to check for internet connectivity before every call to the server. I am doing it using ConnectivityManager and it works.

My problem is actually about notifying user if the internet connectivity is lost. I want to show the user an AlertDialog box telling him about lost internet connection. Now the problem is that if user clicks on a button and a new Activity has to be started(which will load data from server), then I am not able to show him the dialog box on the calling Activity . The catch here is that I don’t want to navigate to other activity if internet is not available. I just want to remain on this activity.

There are a lot of buttons on this activity and on clicking them , user can go to different activities. All I want is not to open other activity if no internet is available and show him the dialog box on this activity only. One way to do it is by checking on every button’s click(in onClick method) and then notifying the user about lost internet connection . But this may be very hectic for me as there are a lot of activities and a lot of buttons in every activity.

Is there a general and efficient way to find out if this activity is being left and a new activity is being started and after finding it, showing dialog box to the user rather than moving to next activity if internet is not available.What are the best practices for handling this issue. Please help me. I am stuck on this for last 2 days. Thanx in advance.

 @Override
  public void onClick(View view) {
    switch(view.getId()){
       case R.id.backIcon:
           navigateMenuScreen(view);
           break;
    }
 }

Here is how I check the internet connectivity(and it works fine):

   ConnectivityManager connectivityManager   = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();

    if (networkInfo!=null && networkInfo.isConnected()) {
        return true;
    } else {
        return false; 
    }

This is the navigation method:

    public void navigateMenuScreen(View view){
    try {           
        Intent loginIntent = new Intent(view.getContext(), MenuActivity.class);      
        startActivityForResult(loginIntent, 0);     
        overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);        
    } catch(Exception ex) {
    }
}

My question is do I have to check internet connectivity in every navigation method(there are other methods like the above one) or is there a better way?

  • 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-10T12:34:18+00:00Added an answer on June 10, 2026 at 12:34 pm

    Register

       registerReceiver(mConnReceiver, 
           new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    

    Listen:

      private BroadcastReceiver mConnReceiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                boolean noConnectivity = intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false);
                String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
                            boolean isFailover = intent.getBooleanExtra(ConnectivityManager.EXTRA_IS_FAILOVER, false);
    
                NetworkInfo currentNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
                NetworkInfo otherNetworkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_OTHER_NETWORK_INFO);
    
                // do application-specific task(s) based on the current network state, such 
                // as enabling queuing of HTTP requests when currentNetworkInfo is connected etc.
            }
        };
    

    And dont forget your manifest file

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I have what must be a very common problem to solve and
This is a very common scenario: displaying images in a ListView which have to
I am having a very common problem which it seems that all the available
This is probably a very common problem which has a lot of answers. I
This is a very common thing in web applications. If I have a user
At first, i have to say that this topic is very common topic. I
i have very serious problem if any tech expert can help...thank you in advance..
I have very strange problem while I am submitting a practice problem on codechef.
I have very little experience with ASP.NET and I am doing some self-training before
This is a very common problem when Excel Worksheet or Chart is embedded into

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.