嗨,我正在处理一个应用程序,因为我在使用
Android WebView.
每当我启动webview活动时,从test.txt文件加载字符串html格式的数据.
test.txt文件包含近2.5 MB的数据,加载test.txt文件后,如果幻灯片屏幕结束读取所有数据并按回来.
然后随后推出的webview活动花费更多的时间来呈现数据.在第一次推出webview时,花费最少的时间.
在启动此活动之前,我没有收到任何错误/异常/崩溃.
我正在使用Android API等级18及以上
我不能使android:hardwareAccelerated =“true”< - 为什么因为它有很多副作用(仍然我使用这个,但没有发现这个问题的变化). 我不能使用
webview.getSettings()setRenderPriority(RenderPriority.HIGH).
setRenderPriority() – > API方法18中已弃用此方法.
不建议调整线程优先级,以后的版本不支持.
我的DataLoader.java类
public class DataLoader extends Activity {
private WebView webView = null;
// Progress Dialog
private ProgressDialog progressDialog;
String dataContent = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.web_view);
webView = (WebView)findViewById(R.id.text);
// Loading webview in Background Thread
new LoadWebView().execute();
}
class LoadWebView extends AsyncTask {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog = new ProgressDialog(DataLoader.this);
progressDialog.setTitle("Loading...");
progressDialog.setMessage("Please wait.");
progressDialog.setCancelable(false);
progressDialog.setIndeterminate(true);
progressDialog.show();
}
protected String doInBackground(String... args) {
// AssetFileReader read the txt file and return data in the form of string
dataContent = AssetFileReader.read(getApplicationContext(), "test.txt");
return null;
}
protected void onPostExecute(String str) {
// dismiss the dialog
progressDialog.dismiss();
if (dataContent != null) {
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
WebSettings s = webView.getSettings();
s.setUseWideViewPort(true);
s.setSupportZoom(true);
s.setBuiltInZoomControls(true);
s.setDisplayZoomControls(false);
s.setJavaScriptEnabled(true);
webView.loadData(dataContent, "text/html", "utf-8");
}
});
}
}
}
@Override
public void onDestroy() {
super.onDestroy();
webView.clearCache(true);
webView.clearHistory();
}
}
我的web_view.xml文件
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/text">
如果您有任何关于这个问题的工作,请让我知道.