Activity跳转到Fragment 然后再返回此Fragment

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35821446/article/details/81033258

此方法可通过广播的形式较为简单,此处用EventBus3.0.0来发广播,

activity中写

if (!EventBus.getDefault().isRegistered(this)) {
   EventBus.getDefault().register(this);
}
@Subscribe
public void onEventMainThread(FriendsSortBackEvent event) {
}
@Override
protected void onDestroy() {
   super.onDestroy();
   if (EventBus.getDefault().isRegistered(this)) {
      EventBus.getDefault().unregister(this);
   }
}

在需要返回Fragment的点击事件里写:

EventBus.getDefault().post(new FriendsSortBackEvent());

Fragment中的代码:

注册和关闭EventBus此处省略....

FriendsSortBackEvent是广播的公共类,(有此类代表在此界面可接受此到广播)此处可封装数据,若无数据,直接为空即可.

此方法里跟新数据即可(或重新请求接口)

@Subscribe
public void onEventMainThread(FriendsSortBackEvent event) {
    getInstantStatus();
    getListData(true);

}


猜你喜欢

转载自blog.csdn.net/qq_35821446/article/details/81033258
今日推荐