I have a WebView which I initialize with loadUrl in AsyncTask.doInBackground. I initialize it like below :
webView.post(new Runnable() {
@Override
public void run() {
webView.loadUrl(authURL);
}
});
AsyncTask is executed as last in Activity.onCreate(), the problem is that most of the time webpage does not get loaded, I see white screen. If I replace webView with handler then all is ok. What am I missing here?
Why are you doing this in doInBackground()
if it needs to run on the UI thread anyway?
The difference between Hander.post()
and View.post()
is that Handler
will run your code
on the thread the Handler
instance was created on (which is not necessarily the UI thread), while View
will always run it on the UI thread (because views are bound to it).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With