runOnUiThread vs Handler.post(runnable action) ?

Put your problem here if it does not fit any of the other categories.

runOnUiThread vs Handler.post(runnable action) ?

Postby matskn » Thu Dec 03, 2009 1:40 pm

Whats the differences/ advantages / drawbacks between using Activity.runOnUiThread(runnable action) or Handler.post(runnable action) in android ?
matskn
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 03, 2009 1:39 pm

Top

Postby appforce » Thu Dec 03, 2009 3:57 pm

Hi,

Activity.runOnUiThread() is actually calling Handler.post() for the UI thread, so they both do the same. Handler.post() is has the only advantage that can be used on different thread if needed.

Android developers
appforce
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Mon Nov 23, 2009 8:28 pm

Postby matskn » Thu Dec 03, 2009 4:33 pm

Hm , interesting.. is this mentioned in the references or something? got a link ? =)
matskn
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 03, 2009 1:39 pm

Postby appforce » Thu Dec 03, 2009 4:37 pm

Hi,

I just looked at the source of Activity.java :)


Android developers
appforce
Experienced Developer
Experienced Developer
 
Posts: 60
Joined: Mon Nov 23, 2009 8:28 pm

Postby matskn » Fri Dec 04, 2009 1:27 pm

http://developer.android.com/reference/ ... ivity.html

Here? couldnt find the information you provided :-/
matskn
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 03, 2009 1:39 pm

Postby grzegorz.zajac » Fri Dec 04, 2009 2:11 pm

Try here:

Activity.java

Regards,
Grzesiek
grzegorz.zajac
Developer
Developer
 
Posts: 39
Joined: Wed Feb 18, 2009 8:37 pm
Location: Krakow/Poland

Top

Postby matskn » Fri Dec 04, 2009 2:20 pm

Neat! Thanks alot!
matskn
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 03, 2009 1:39 pm

Postby matskn » Sat Dec 05, 2009 11:51 am

A followup here.. When do you use the Activity.runOnUiThread and when do you use handler? And also i discovered the View.postRunnable(). I checked the source code and it also uses a handler to post the runnable. So my question is.. when should i use View.post.. Activity.runon.. and Handler.post?

tnx in advance!
matskn
Freshman
Freshman
 
Posts: 6
Joined: Thu Dec 03, 2009 1:39 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests