有个需求:切换车队身份实现Fragment的Tab隐藏显示(车队不显示奖赏)
核心实现:
1使用mmkv保存切换的身份
2借助eventbus实现通知Fragment的tab更新
private void switchFleet(boolean isMore, EnterpriseInfo enterpriseInfo) {if (isMore) {tvSwitchFleetTitle.setText(getText(R.string.switch_to_other_accounts));} else {tvSwitchFleetTitle.setText(getText(R.string.switch_to_personal));}new MMKVUtils().putBoolean("car",true);MessageEvent messageEvent = new MessageEvent();messageEvent.mMessagecount=2;EventBus.getDefault().post(messageEvent);SwitchingIdentitiesUtils.switchIdentities(2,enterpriseInfo.getBusUnitId());}
@Subscribe(threadMode = ThreadMode.MAIN)public void onMessageEvent(MessageEvent event) {
// if (event.mMessagecount == 2) {
// Log.e("wy", "103 onMessageEvent 车队身份: ");
// isCar = true;
// } else {
// Log.e("wy", "110 onMessageEvent 不是车队身份: ");
// isCar = false;
// }initTitles();initFragment();initTabAndViewPager();}