java - Will Runnables block the UI thread? -
i trying understand how ui thread's event queue works. i'm trying run code can broken many parts unfortunately must run on ui thread. so, in order not block ui thread , receive anr wondering if can break code in many runnable objects , run them using runonuithread thread.
my question is, block ui thread? if, example, have piece of code runs in on 5 seconds , break code into, let's 1000 runnable objects, , add them event queue of ui thread, other events processed ui thread between them?
edit: think found better way express myself in case above explanation confusing.
- the 1000
runnableobjects example, in actual code want have @ 10. - basically, want 10
runnableobjects, each 1 initialising ad network on ui thread. want theserunnableobjects run 1 after another, not in parallel. also, want ui thread able process other events between running these objects, don't anr in case running 10runmethods take more 5 seconds.
note: don't know why initialising ad networks must done on ui thread, must, otherwise app crashes. states in of networks' sdks' documentation initialisation must happen on ui thread. why need run them 1 after on ui thread , can't run them in parallel in background. also, app opengl game, calls running runnable objects made gl thread, not main thread, added event queue, , not executed immediately.
what looking asynctask.
these designed background processing, while ui thread continues. not block ui , not cause anr.
within asynctask, onpostexecute method, allows post results ui. not detached ui thread. , onprogressupdate connection during background processing
Comments
Post a Comment