WebView takes approx. 10 second time to load Html Page from Assets
folder in real android device greater than 4.3....
My WebView activity are as follows:-
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import android.widget.Toast;
public class Activity_WebView extends ActionBarActivity {
boolean loadingFinished = true;
boolean redirect = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_webview);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
TextView app_Title = (TextView) toolbar.findViewById(R.id.toolbar_title);
app_Title.setVisibility(View.VISIBLE);
Intent intent = getIntent();
String TITLE = intent.getStringExtra("Title");
String URL_PATH = intent.getStringExtra("Url_Path");
WebView webview = (WebView) findViewById(R.id.webView);
webview.getSettings().setJavaScriptEnabled(true);
webview.setBackgroundColor(getResources().getColor(android.R.color.transparent));
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webview.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
try {
if (Build.VERSION.SDK_INT > 14) {
webview.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
}
} catch (Exception e) { e.printStackTrace();}
GlobalVariablesCollection.globalPD = CustomProgressBarDialog.showProgressDialog(Activity_WebView.this);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
app_Title.setText(TITLE);
webview.loadUrl(URL_PATH);
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (!loadingFinished) {
redirect = true;
}
loadingFinished = false;
view.loadUrl(url);
return true;
}
@Override
public void onPageStarted(WebView view, String url, Bitmap facIcon) {
loadingFinished = false;
//SHOW LOADING IF IT IS NOT ALREADY VISIBLE
GlobalVariablesCollection.globalPD.show();
}
@Override
public void onPageFinished(WebView view, String url) {
if (!redirect) {
loadingFinished = true;
}
if (loadingFinished && !redirect) {
//HIDE LOADING IT HAS FINISHED
GlobalVariablesCollection.globalPD.dismiss();
} else {
redirect = false;
}
}
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
Toast.makeText(getApplicationContext(), "Oh no! " + description, Toast.LENGTH_SHORT).show();
alertDialog.setTitle("Error");
alertDialog.setMessage(description);
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
return;
}
});
alertDialog.show();
}
});
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
this.finish();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
My Requirement: WebView should display Html Page on
onPageFinished