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

  • Home
  • SEARCH
  • 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 8304285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:48:07+00:00 2026-06-08T17:48:07+00:00

I need to detect whether the Android device is connected or disconnected to the

  • 0

I need to detect whether the Android device is connected or disconnected to the internet on splash… if there’s no connection, the application won’t open.. i have try many time.. but i failed.. this is my splash’s source code :

private Handler splashHandler = new Handler();
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Runnable r = new Runnable(){
        public void run(){
            Intent brain = new Intent(Splash.this, MainMenu.class);
            startActivity(brain);
            finish();
        }
    };
    setContentView(R.layout.splashscreen);
    splashHandler.postDelayed(r, 2000);
}

public void onResume(Bundle savedInstanceState){
    super.onResume();
}

}

if there’s someone help me and give me a source code.. tell me where i must put it..

  • 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-08T17:48:09+00:00Added an answer on June 8, 2026 at 5:48 pm

    From this SO Post: Detect whether there is an Internet connection available on Android

    Here is what your code should look like:

    private Handler splashHandler = new Handler();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Runnable r = new Runnable(){
            public void run(){
                Intent brain = new Intent(Splash.this, MainMenu.class);
                startActivity(brain);
                finish();
            }
        };
        setContentView(R.layout.splashscreen);
        if(isNetworkAvailable())
            splashHandler.postDelayed(r, 2000);
        else {
            //Notify user they aren't connected
            Toast.makeText(getApplicationContext(), "You aren't connected to the internet.", Toast.LENGTH_SHORT).show();
            //close the app
            finish();
        }
    }
    
    public void onResume(Bundle savedInstanceState){
        super.onResume();
    }
    
    private boolean isNetworkAvailable() {
        ConnectivityManager connectivityManager 
          = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
        return activeNetworkInfo != null;
    }
    

    As stated in the link above, you’ll also need to add:

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

    to your AndroidManifest.xml file…

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

Sidebar

Related Questions

I need to detect android device orientation change without playing manually with sensor data,
I have a problem where I need to detect whether a given type is
In a .NET application I am writing, I need to detect whether a particular
I need to tell if my device has Internet connection or not. I found
I have a flash app and I need to detect whether the streaming of
I need to detect whether my application is running within a virtualized OS instance
In my application I need to detect whether my application is going to background
I need to feature detect whether a browser supports svg filters (feGaussianBlur, to be
I need to be able to detect whether the current language my user is
I need to detect IE7 (and IE6) using the user agent string: I have

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.