Android EventBus, priority of Subscriber not working

177
December 08, 2017, at 1:18 PM

I am working with android and the EventBus library. There are some events I want my fragment to be subscribed to, but I want to make sure that when the fragments go live, subscriber1 receives its event before subscriber2 does. The problem is no matter what priority value I set to the subscribers, subscriber2 is always receiving his event before subscriber1.

public class HomeFragment extends Fragment {
    private EventBus bus = EventBus.getDefault();
    Data data;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    {
    View v = inflater.inflate(R.layout.fragment_home, container, false);
    return v; 
    }
    @Override
    public void onStart() {
        super.onStart();
        bus.register(this)
    }
    @Override
    public void onStop() {
        bus.unregister(this);
        super.onStop();
    }
    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN, priority = 10)
    public void subscriber1 (Data event) {
        data = event;
        loadDataOnUI(data);
    }
    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void subscriber2(Global event) {
        if (data == null) {
            getData(event.getLastname()); //function getData is an API request. 
                                          //On response it uses bus.postSticky(response.body()), to publish the Data event an update the UI. 
        }
    }
}

I am implementing this event-subscriber pattern with the goal of saving API requests to the server if the data was already loaded before (I have no intention on persisting the data beyond a temporary cache-like use). So I use .postSticky(data) to keep the data available in the session. Can someone please help me to realize what am I doing wrong?

READ ALSO
How can i detected a global swipe?

How can i detected a global swipe?

Ok so I have been writing a simple navigation overlay app for Android as a proof of conceptUsing a service I can make my overlay stay on top of any app that is launched

168
How can I chain a list of Completable after executing another Completable

How can I chain a list of Completable after executing another Completable

I am trying to save some data in a databaseFor adding methods I use Completable

145
How does SpeechRecognizer in Android work [on hold]

How does SpeechRecognizer in Android work [on hold]

Can anyone tell me the SpeechRecognizer in Android uses a service from internet to convert speech to text

131
How to display Edittext in Android [duplicate]

How to display Edittext in Android [duplicate]

This question already has an answer here:

173