I'm having a IntentService to perform background request to my API. I'm using Otto Bus to communicate with 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 is performed on a secondary thread, which is normal. But when i call onLoadSearchData with a bus event from the main ui, it runs on the UI thread !!!!
I don't understand why.
My purpose is to have a background thread to load/cache data.
Not sure how to do this. Thanks for the help.