Splash screen completely white?

Go To StackoverFlow.com

3

Basically I have a splash screen that shows when the user launches the app. The splash screen is supposed to open a website (a website that will be shown later) to download all fonts and images to cache to make everything run smoother the first time you run the app. But all you see is a white screen at the moment, the code works (tested it) but it shows a white splash screen instead of one with a logo and some text on it.

Here's the code;
Splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="#4A4A4A">

    <ImageView
        android:id="@+id/logo"
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:src="@drawable/logo"
        android:layout_gravity="center" />

    <TextView
        android:text="@string/loading"
        android:layout_gravity="center"
        android:textColor="#FFA500"
        android:textSize="15dp"
        android:typeface="normal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <WebView
        android:id="@+id/splashview"
        android:layout_width="0px"
        android:layout_height="0px"
        android:layout_weight="0" />

</LinearLayout>


Splash.java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Splash extends Activity {
    @Override
    protected void onCreate(Bundle savedInstance) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstance);
        setContentView(R.layout.splash);

        WebView webView = (WebView) findViewById(R.id.splashview);
        webView.setWebChromeClient(new WebChromeClient());

        webView.loadUrl("http://ngmat.site90.net/matsedel/");

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageFinished(WebView view, String url) {
                Intent NGMat = new Intent("android.intent.category.SECONDARY");
                startActivity(NGMat);
            }
        });

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }

    @Override
    protected void onResume() {
        super.onResume();
        setContentView(R.layout.main);
    }

}
2012-04-05 01:34
by Unidan


3

I just tried opening your URL in a normal desktop browser and got absolutely nothing displayed for quite a while, almost until whatever needed to be downloaded was finally downloaded. So there is a delay problem.

The web view is a strange beast. It seems to me that you give it HTML (or in your case an external URL) and it returns from the loadUrl call almost immediately. Then on another thread the web view figures out what it wants to render, and then renders it. Therefore there is often a delay between the loadURL() call returning and the screen actually updating. In my apps I have the HTML/CSS all in one string and so there is no "download" delay, and yet still there can be a perceptible delay between the screen showing and the web view rendering.

And your site appears to have a download delay to add to the web view's natural delay. I suspect that the web view is being made visible, it doesn't have anything to display yet so renders a blank/white screen, then does the download of the HTML/whatever from the external website, still displaying a blank screen until it has everything downloaded and is ready to render something onto the screen except your next activity is invoked via the onPageFinished() web view client method.

The UI thread seems to figure out that another UI affecting thread is running (the start of the next activity) and thus does not actually update the screen knowing that it will be overwritten anyway. Thus your screen stay blank/white while the new activity starts and finishes its onCreate(), onStart(), etc sequence of calls to finally update the screen.

Therefore you will never see your splash screen. The web view doesn't get a chance to update the screen because the next activity takes control of screen.

Unfortunately I think that your approach is flawed. I think it would be better to split the approach into two - load the splash screen with something really simple, and then on a background thread cause the data download to occur. Have the background thread invoke the secondary activity when it has completed everything, ideally by posting a call to the UI thread to switch to the next activity.

This way the user will get to see something, and then in the background the other stuff happens while the user is admiring your splash screen.

Could you embed the splash screen content in the application's downloaded/installed package so that it is always displayed quickly without being affected by the presence of a data connection, or its speed? Often apps have a simple splash screen "burnt into" the installed package so that they have something to show regardless of the device's ability to reach outside of itself.

2012-04-05 01:59
by Colin
Hey. Thanks for the answer! Right now the splash screen is shown like I want to and it actually caches the web content but there's a 0.5 second of white screen showing after the splash, but I can live with that.. Now my problem is that the splash screen is shown everytime the app is opened even if the content has been cached so Im trying to figure out what to do. I was thinking about 'SharedPreferences', need to read a bit more about it first - Unidan 2012-04-05 02:11
The app will only know that the cached content is the right content to use once it has enough information from the external web server to realize that it has the data that it needs. You know that the URL is a repeat URl and that the content behind it has not changed, but the webview does not - it has to interact with your external web server to figure that out, and that could take a little while especially if the server or data network (latency) is slow - Colin 2012-04-05 02:17


0

I think the setContentView(R.layout.main) line in onResume might be causing the problem. You're already calling setContentView(R.layout.splash) in onCreate so you don't need to call it again in onResume. Not sure what your main.xml looks like, but seems like it might just be a blank layout.

2012-04-05 01:40
by Aldryd
I removed the whole onResume and now it works! Thanks for the quick answer. But now everytime i launch the application it shows the splash screen. Should I make a boolean to check if splash is already shown - Unidan 2012-04-05 01:43
Saving a boolean in SharedPreferences is one way to do that, but as @Colin mentioned, you don't necessarily know that you've cached the right data. For instance, if you load the app while that site is down or you don't have a connection, you could end up setting the flag to never show the splash screen even though it never cached the data you wanted. Not sure of the details of your use case here, but I just wanted to mention some things to consider - Aldryd 2012-04-05 15:06


0

Maybe page loaded too fast? What about timer at 3-5 seconds before start loading content?

2012-04-05 01:43
by Roman Truba
Ads