Splash image is not displayed when charging App on mobile

1

I have a code that I took out of a tutorial that supposedly causes the splash image to be displayed while a WebView is loaded, and that when it finishes loading, the splash is hidden:

@Override
public void onPageFinished(WebView view, String url) {
       findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
       findViewById(R.id.splashLoading1).setVisibility(View.GONE);
}

However, this never appears when trying the app on my cell phone. The full code of the main_activity is this:

public class MainActivity extends Activity {

    private WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.activity_main_webview);
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.chapatelo.com.ar/");
        mWebView.setWebViewClient(new MyAppWebViewClient(){
            @Override
            public void onPageFinished(WebView view, String url) {
                findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
                findViewById(R.id.splashLoading1).setVisibility(View.GONE);
            }
        });
    }

    @Override
    public void onBackPressed(){
        if(mWebView.canGoBack()){
            mWebView.goBack();
        }else{
            super.onBackPressed();
        }
    }

    private class MyAppWebViewClient extends WebViewClient{}
}

and the activity_main.xml is as follows:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.chapatelo.www.chapatelo.MainActivity">

<ImageView
    android:id="@+id/splashLoading1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="visible"
    android:src="@mipmap/splash"
    android:contentDescription="@string/desc"/>

<WebView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/activity_main_webview"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

In summary, my doubts are the following:

1) Am I placing the ImageView in the correct position (above the webview)?

2) Is there a function missing from the main_activity.java so that the splash is displayed and then hidden when the webview is finished loading?

Note: Android Studio does not throw me any errors and compiles the app correctly as I have it, only that the Splash image is never displayed.

    
asked by Criss 29.05.2016 в 21:51
source

1 answer

1

This is incorrect because at the beginning of your activity, load a page and when it finishes loading in the WebView you are making visible the WebView and invisible the ImageView that contains your Splash image and this can happen in a short time:

@Override
public void onPageFinished(WebView view, String url) { 
   findViewById(R.id.activity_main_webview).setVisibility(View.VISIBLE);
findViewById(R.id.splashLoading1).setVisibility(View.GONE);
}
    
answered by 29.05.2016 в 22:12