0
votes

I have a splash screen image in onCreate (MainActivity).

I want the image to remain until the second activity (URL-Browser) finishes loading.

Is there some way to pre-execute it and load after few seconds.

All the examples i see have a splash screen running for few seconds and then start the second activity but not preexecute.

How do I do that?

3
What is the URL-Browser? I used to put a layout on my activity, with the splash screen, and when the activity finished the loading, I removed the upper layout with setVisibility(View.GONE); in a callback function. - Nagy Vilmos
URL is the website link I want to load using a webview. Is it possible to change the layouts programmatically having an image in the 1st layout and the webview in the 2nd. - Vinay Potluri

3 Answers

0
votes

Instead of having a splash screen with only an image (possibly your current splash screen), you should start your actual activity and display the image you use in your splash screen. Once everything is loaded you need for that activity, you can remove the image from the main activity.

0
votes

Alternatively, load a fragment in your activity which displays the splash screen. Have the fragment load whatever you need loading using an async task. On the callback from the async task unload the splash screen fragment and load a new fragment with whatever you need to show.

0
votes

you can use an async task; here is an example;

private AsyncTask<String, Integer, String> xTask = new AsyncTask<String, Integer, String>() {
    @Override
    protected String doInBackground(String... strings) {
        //you can just sleep a while to show your splash
        return null;
    }

    @Override
    protected void onPostExecute(String s) {
        //do something as the execution completed, you can launch your real activity.
    }
};

and on you activities onResume

@Override
public void onResume() {
    if(xask.getStatus().equals(AsyncTask.Status.PENDING)) xTask.execute();
    super.onResume();
}