KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I'm developing a small app that reads in specific html-pages, re-formats them and then shows them in a WebView. If I run my code in the GUI thread, the performance hit is close to negligible compared to simply letting the WebView show the original html-page. But if I'm a good boy and do like I'm told, I'm supposed to use an AsyncTask to run the code in the background so as not to freeze up the GUI during those 3-5 seconds my code does its job. Problem is... if I do so, the code takes more than 10 times as long to finish. A page takes 60+ seconds to show, which is unacceptable. Tracking down the problem, TraceView shows me that my AsyncTask is (at default priority) run in roughly 10 ms chunks, around 4 times per second. I need to set my thread priority to MAX_PRIORITY to get close to acceptable loading times, but even then it takes 3-4 times longer than when I run in the GUI thread. Am I doing something wrong, or is this just the way it works? And must it work this way...? Here's compilable code as requested: package my.ownpackage.athome; import android.app.Activity; import android.os.AsyncTask; import android.os.Bundle; import android.os.StrictMode; import android.webkit.WebView; import android.webkit.WebViewClient; public class AndroidTestActivity extends Activity { WebView webview; //... private class HelloWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { AndroidTestActivity.this.fetch(view, url); return true; } } public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // To allow to connect to the web and pull down html-files, reset strict mode // see http://stackoverflow.com/questions/8706464/defaulthttpclient-to-androidhttpclient if (android.os.Build.VERSION.SDK_
Tags (comma-separated)
Save Edits
Cancel