Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between widget post() vs. handler post()?

Tags:

android

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?

like image 912
marcinj Avatar asked Oct 14 '12 18:10

marcinj


1 Answers

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).

like image 197
Nikolay Elenkov Avatar answered Nov 13 '22 15:11

Nikolay Elenkov