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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:14:28+00:00 2026-05-26T01:14:28+00:00

I am stuck with following problem.I want my application to exit if it detects

  • 0

I am stuck with following problem.I want my application to exit if it detects no network connection.My application starts with splash screen.Is it possible to show splash screen followed by toast if no network connection is on device.and then terminate the application

I have something like this in my splash screen code :

Inside onCreate()

ConnectivityManager connectivitymanager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo networkinfo = connectivitymanager.getActiveNetworkInfo();
        connected = networkinfo != null && networkinfo.isAvailable()
                && networkinfo.isConnected();
        Log.v("Network state : ", connected + "");

        Thread splashThread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;
                    while (waited < 5000) {
                        sleep(100);
                        waited += 100;
                    }
                } catch (InterruptedException e) {
                    // do nothing
                } finally {
                    Looper.prepare();
                    if (connected == false) {
                        Toast.makeText(
                                splashscreenActivity.this,
                                "No Network Connection is available on device.",
                                Toast.LENGTH_LONG).show();
                        finish();
                        System.exit(0);
                    } else {
                        finish();
                        startActivity(new Intent(splashscreenActivity.this,
                                mainActivity.class));
                    }
                    Looper.loop();
                }
            }
        };
        splashThread.start();

1.Please see my code and guide me how can i show up that toast.
2.Or suggest me some other better way to do this

Thanks

EDIT :

Thank you everybody for replying :

I opted Dharmendra’s way of showing toast via splashscreen activity :

The code that worked for is :

if (connected == false) {
            splashscreenActivity.this.runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    Toast.makeText(splashscreenActivity.this,
                            "No Internet Connection.", 3000).show();
                }
            });
            finish();
        } else {
            //migrate to main activity from splashscreen
        }
  • 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-26T01:14:29+00:00Added an answer on May 26, 2026 at 1:14 am

    You are creating and showing Toast from Thread so it may be not called

    You have to write this code

    splashscreenActivity.this.runOnUiThread(new Runnable() {
    
                    @Override
                    public void run() {
                        Toast.makeText(c, "Internet connection not currently available.", 3000).show();
                    }
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am stuck in the following problem from a long time - I want
I am stuck in a problem with an application. I have following lines of
I'm new to wicket and stuck with the following problem: I have a table
I'm a beginner programmer and I'm stuck with the following problem: If I have
I am trying to use Hibernate+Spring in my application but stuck into following error:
I have a problem on the following situation: In my Spring, Hibernate application I
I am stuck with following monad problem: Let's say I have a standard monad
I am stuck and need outside help from JSF experts with the following problem:
hi i am in mobile app and i have the following problem. i want
I'm stuck with the following problem. My backend (Java sevlet) returns from a database

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.