java - Android runOnUiThread execution sequence -
runonuithread(new runnable(){ @override public void run() { system.out.println("print out runonuithread."); } }); system.out.println("print out in main thread.");
**output:** print out runonuithread. print out in main thread.
runonuithread
used in background thread, doing testing only.
the code above execute in activity
oncreate
method.
from output, result not expect. thinking that, since runonuithread
post runnable
block main thread, , current execution context in main thread already, runonuithread
should scheduled after "print out in main thread", why result doesn't show that? interpret wrongly? can kindly explain?
edit:
oh should read api first. anyway, why confuse me because, in ios, similar mechanism behave differently:
dispatch_async(dispatch_get_main_queue(), ^{ nslog(@"main thread dispatch."); }); nslog(@"main thread.");
the output of above reversed.
runonuithread:
runs specified action on ui thread. if current thread ui thread, action executed immediately. if current thread not ui thread, action posted event queue of ui thread.
activity oncreate()
method runs in ui thread. first runonuithread
code run rest of code.
Comments
Post a Comment