嘿,我正面临加载时间问题我正在使用此代码我尝试了大部分的东西,但仍然问题是相同的。即使我将加载亚马逊网站然后它将需要10分钟上传
package com.example.app;
import java.util.Timer;
import java.util.TimerTask;
import com.example.app.BookMyShow.myWebClient;
import android.app.Activity;
import android.app.ListActivity;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MakeMyTrip extends Activity {
private WebView mWebView;
public static final String PREFS_NAME = "LoginPrefs";
SharedPreferences settings;
String query="http://freekabalance.blogspot.in";
SharedPreferences.Editor editor;
ProgressBar progressBar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.freekabalance);
settings = getSharedPreferences(PREFS_NAME, 0);
editor = settings.edit();
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new myWebClient());
mWebView.loadUrl(query);
}
public class myWebClient extends WebViewClient
{
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
// TODO Auto-generated method stub
super.onPageStarted(view, url, favicon);
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// TODO Auto-generated method stub
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
progressBar.setVisibility(View.GONE);
}
}
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
return;
}
// Otherwise defer to system default behavior.
super.onBackPressed();
}
}
我也试过了,但它没有用
mWebView.setInitialScale(1);
mWebView.getSettings().setAppCacheMaxSize( 5 * 1024 * 1024 ); // 5MB
mWebView.getSettings().setAppCachePath( getApplicationContext().getCacheDir().getAbsolutePath() );
mWebView.getSettings().setAllowFileAccess( true );
mWebView.getSettings().setAppCacheEnabled( true );
mWebView.getSettings().setCacheMode( WebSettings.LOAD_DEFAULT );
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.getSettings().setUseWideViewPort(true);
我也尝试了这个,但它无法正常工作
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
答案 0 :(得分:0)
我尝试了这个并帮助了我:
webview.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
if (Build.VERSION.SDK_INT >= 19) {
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
}
else {
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
答案 1 :(得分:0)
我是guest,您不想处理特殊的网址格式,因此您无需在方法view.loadUrl(url)
内调用shouldOverrideUrlLoading
,
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}