Screen splash completely white?

Basically I have a splash screen showing when the user launches the application. The splash screen is supposed to open up a website (a website that will be shown later) to load all fonts and images into the cache to keep things smooth the first time you launch 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);
    }

}

      

+3


source to share


3 answers


I just tried opening your URL in a normal desktop browser and got absolutely nothing displaying for quite some time, almost until the download was finally loaded. So there is a latency issue.

Web browsing is a strange beast. It looks to me like you are giving it HTML (or in your case an external URL) and it returns immediately from the call to loadUrl. Then on another thread, the web view determines what it wants to display and then displays it. Therefore, there is often a delay between the return of the loadURL () call and the actual screen refresh. In my applications, I have HTML / CSS all on one line and therefore there is no "loading" delay, and yet there can be a noticeable delay between the screen and the rendering of the web view.

And your site seems to have a load delay to add to the natural latency of the web view. I suspect the web view becomes visible, it has nothing to display it, so it displays a blank / white screen and then loads HTML / something from an external website, still displaying a blank screen until it everything will be loaded and ready to display something on the screen, except that your next activity is called using the client's onPageFinished () method.

The UI thread seems to detect that another UI is running affecting the thread (starting the next activity) and thus doesn't actually update the screen, knowing that it will be overwritten anyway. This way your screen stays blank / white when a new activity starts and ends with it with a sequence of calls onCreate (), onStart (), etc. to finally refresh the screen.



Therefore, you will never see your splash screen. Webview does not provide an option to refresh the screen because the next action controls the screen.

Unfortunately, I believe your approach is flawed. I think it would be better to split the approach in two - load a splash screen with something very simple and then call the data load on a background thread . If a background thread invokes secondary activity when it has completed everything, ideally by sending a call to the UI thread to proceed to the next activity.

This way the user will see something and then in the background other stuff happens when the user admires your splash screen.

Could you include the splash screen content in your downloaded or installed app package so that it always displays quickly without being affected by your data connection or speed? Applications often have a simple splash screen "burned" in the installed package so that they have something to show regardless of the device's ability to reach outside of itself.

+3


source


I think the line setContentView(R.layout.main)

in onResume

might be causing the problem. You are 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 it looks like it might just be an empty layout.



0


source


Is the page loading too fast? How about a timer 3-5 seconds before the content starts loading?

0


source







All Articles