Search code examples
androidandroid-adaptermvpevent-bus

Android : best case for communicating adapter with Activity/Fragment


In MVP pattern, action from user must deliver to presenter

so in listView when user click on item I want send this action to presenter

what is the best case for communicating adapter with Activity/Fragment?

and I appreciate it if you explain pros and cond of each one.

  1. EventBus
  2. CallBack

Solution

  • Depending on your scenario u can adopt given below methods

    Try using an interface
    

    https://stackoverflow.com/a/16443645/4247543

    if the above method is not helping then try using EventBus
    

    please follow below link to know more of Event Bus

    https://github.com/greenrobot/EventBus

    http://gunhansancar.com/ease-communication-between-activities-fragments-services/

    BroadcastReceiver as mentioned could also help for enabling communication.
    

    https://stackoverflow.com/a/10084754/4247543

    You can use observers
    

    https://stackoverflow.com/a/30964385/4247543

    Hopes it helps.