Reaching-Out
Reaching-Out

Reputation: 415

To load splash screen till webview is loaded

Created an android app in which I have a website loaded through webview. I have made my splash screen to load for 5 seconds and have put progress bar in between so that the time taken by the website to load is adjusted.

Now I need to display the splash screen till the page is loaded and have decided to remove the progress bar page. I am working with the following code.

public class Splashscreen extends Activity {

// Set Duration of the Splash Screen
long Delay = 5000;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Remove the Title Bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    // Get the view from splash_activity.xml
    setContentView(R.layout.splash);

    // Create a Timer
    Timer RunSplash = new Timer();

    // Task to do when the timer ends
    TimerTask ShowSplash = new TimerTask() {
        @Override
        public void run() {
            // Close SplashScreenActivity.class
            finish();

            // Start MainActivity.class
            Intent myIntent = new Intent(Splashscreen.this,
                    MainActivity.class);
            startActivity(myIntent);
        }
    };

    // Start the timer
    RunSplash.schedule(ShowSplash, Delay);
}
}

Where should I make the change ?

Upvotes: 0

Views: 1723

Answers (3)

user16224886
user16224886

Reputation: 1

Please look this link on how to display a progress bar till webview load the page
https://medium.com/android-news/loading-splash-screen-for-webview-in-android-studio-ef68ec05720a.

Upvotes: 0

Vivek Mishra
Vivek Mishra

Reputation: 5705

You have to make splash screen and web view in same activity. And to know when page finished loading,You can use this method with your webview.

 webview.setWebViewClient(new WebViewClient() {
   @Override
   public void onPageFinished(WebView view, String url) {

    }
});

Inside onPageFinished() Method you can dismiss your progress bar

Upvotes: 1

Knossos
Knossos

Reputation: 16058

You cannot load a WebView from another Activity whilst you are in your Splashscreen. You instead need to load your MainActivity and overlay your splash screen on your WebView.

Upvotes: 1

Related Questions