How to send event from Service to Activity with Otto event bus?

后端 未结 7 1752
心在旅途
心在旅途 2020-12-02 05:19

Simple BusProvider.getInstance().post() bring exception not main thread. How to send event from Service to Activity with Otto event bus?

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-02 05:58

    Or simply do this if you're sure that you're posting from a Non-main thread:

    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            mBus.post(new myEvent());
                        }
                    });
    

    Just as the saying goes, "Keep It Simple and Stupid" :)

提交回复
热议问题