Search code examples
androidwebviewsplash-screen

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 ?


Solution

  • 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.