multithreading - Android - IntentService runs on UI thread when called with bus event -


i'm having intentservice perform background request api. i'm using otto bus communicate it.

public class myservice extends intentservice {      private myapi mapi;     private mybus mbus;      myservice () {         super("myservice ");     }      @subscribe     public void onloadsearchdata(loadsearchdataevent event) {         log.d("onloadsearchdata "+ thread.currentthread().getname());         mapi.loadsomedata();     }       @override     protected void onhandleintent(intent intent) {         thread.currentthread().setname(getclass().getcanonicalname());         log.d("thread name " + thread.currentthread().getname());         if (mapi==null) mapi = new myapi(getapplicationcontext());         if (mbus==null) {             mbus = mybus.getinstance();             mbus.register(this);         }     }  } 

the onhandleintent performed on secondary thread, normal. when call onloadsearchdata bus event main ui, it runs on ui thread !!!!

i don't understand why.

my purpose have background thread load/cache data.

not sure how this. help.

i don't understand why.

quoting the otto documentation:

by default, interaction instance confined main thread

more specifically, otto delivers messages on same thread posted from.

my purpose have background thread load/cache data.

intentservice has background thread, invoke onhandleintent(). once onhandleintent() returns, not thread go away, service gets destroyed.

i unclear why think need service here. assuming do, need use regular service , arrange own background thread, can better control lifetime of service , thread.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -