AndroidFragment执行finish()后,回退到另一个Fragment实现更新数据

    xiaoxiao2022-05-20  218

    fragment 执行finish方法后的代码:

    getActivity().finish(); Intent intent = new Intent("android.intent.action.CART_BROADCAST"); intent.putExtra("data","refresh"); LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(intent); getActivity().sendBroadcast(intent);

    回退到的fragment的代码:

    @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); LocalBroadcastManager broadcastManager = LocalBroadcastManager.getInstance(getActivity()); IntentFilter intentFilter = new IntentFilter(); intentFilter.addAction("android.intent.action.CART_BROADCAST"); BroadcastReceiver mItemViewListClickReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent){ String msg = intent.getStringExtra("data"); if("refresh".equals(msg)){ refresh();//实现操作数据刷新的方法 } } }; broadcastManager.registerReceiver(mItemViewListClickReceiver, intentFilter); }

    原文章出处:https://www.cnblogs.com/shmilyGWT/p/8274610.html


    最新回复(0)