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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:46:11+00:00 2026-06-03T19:46:11+00:00

I’ve got an Android app that uses a WebView. At the startup of the

  • 0

I’ve got an Android app that uses a WebView. At the startup of the app it checks if the WebView can connect to the server or not. If it can connect there’s no problem, the app loads instantly and the WebView is showing the page. But if the server is not available or the connection doesn’t work, it takes a few seconds (5-10) before the error message shows. That’s because when you have a slow connection, it doesn’t show the error message continiously.

So with no connection you see a black screen for about 5-10 seconds. What I want is just a simple loading dialog at the startup of the app. So that you don’t see the black screen and people know the app is doing something. How can I archieve this with the most simple but effective way??

Thank you!!

EDIT:

Okay this is what I now have, I think it’s working but is this the right way? And is it possible to use this Async thread also in the shouldOverideUrlLoading? How can I do that?

public class WebviewActivity extends MainActivity {

    private WebView myWebView;
    private ProgressDialog progressDialog;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);

        final ScrollView mainScrollView = (ScrollView)findViewById(R.id.ScrollView01);

        myWebView = (WebView)findViewById(R.id.webview);
        WebSettings webSettings = myWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);

        progressDialog = ProgressDialog.show(WebviewActivity.this, "", "Loading...", true);

        myWebView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                progressDialog.show();

                if ( isOnline() == false || isOnlineHost() == false )
                    myWebView.loadUrl("file:///android_asset/errorpage.html");
                else
                    view.loadUrl(url);

                return true;                
            }
            @Override
            public void onPageFinished(WebView view, String url) {
                progressDialog.dismiss();
                mainScrollView.fullScroll(ScrollView.FOCUS_UP);
            }
        });

        myWebView.requestFocus(View.FOCUS_DOWN);
        myWebView.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                    case MotionEvent.ACTION_UP:
                        if (!v.hasFocus()) {
                            v.requestFocus();
                        }
                        break;
                }
                return false;
            }
        });
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig){        
        super.onConfigurationChanged(newConfig);
    }

    @Override
    public void onResume() {
        super.onResume();    
        new checkConnection().execute();
    }

    //DOING THE CONNECTION CHECK IN ANOTHER THREAD  
    public class checkConnection extends AsyncTask<String, Integer, String>{        

        private ProgressDialog progressDialog;              

        protected void onPreExecute(){
            progressDialog = ProgressDialog.show(WebviewActivity.this, "", "Loading...", true);
            progressDialog.show();
        }

        @Override
        protected String doInBackground(String... params) {
            if ( isOnline() == true && isOnlineHost() == true )
                myWebView.loadUrl(webLink);
            else
                myWebView.loadUrl("file:///android_asset/errorpage.html");

            progressDialog.dismiss();           
            return null;
        }       
    }
}
  • 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-03T19:46:12+00:00Added an answer on June 3, 2026 at 7:46 pm

    Use an AsyncTask to check for the connectivity in the background while the ProgressDialog is shown. Dismiss the dialog after the check is complete.

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

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

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.