What's the difference between in post(Runnable r) to main thread's handler and running in main thread
//case 1:post to main thread's handler
mHandler.post(new Runnable(){
public void run(){
dosomething(); //开发者_开发问答update UI
});
//case 2:run in main thread
dosomething();
Even if you are on the handler's thread, case 1 will be queued and case 2 will be executed immediately.
Well, if you're in the main thread, then you're in the main thread, so that's fine.
But pretty often, you're in a worker thread and want to do something that can only be done in the main thread (like updating the UI). In those cases, you need to do something special to run your code on the main thread - the handler code you posted would be one example.
精彩评论