Activity跳轉到Fragment 然後再返回此Fragment
阿新 • • 發佈:2018-12-13
此方法可通過廣播的形式較為簡單,此處用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是廣播的公共類,(有此類代表在此介面可接受此到廣播)此處可封裝資料,若無資料,直接為空即可.
此方法裡跟新資料即可(或重新請求介面)
@Subscribepublic void onEventMainThread(FriendsSortBackEvent event) { getInstantStatus(); getListData(true); }