Activity And Fragment Interaction

前端 未结 7 1272
南旧
南旧 2020-12-10 12:54

I have an Activity with multiple Fragments. I want to show a DialogFragment or open another Fragment from one of the

7条回答
  •  温柔的废话
    2020-12-10 13:44

    To get a maximum in loose coupling you can use an event bus like OTTO from Square or EventBus from GreenRobot. Your fragments can fire events which are handled by your activity and vice versa. The cool thing about this is that the components (activities, fragments) no nothing about each other and you do not need to declare any interfaces or callbacks.

    I use it in all my projects and it is robust and has low to no influence on the performance (in normal conditions).

提交回复
热议问题