public class DeliverFragment extends Fragment {
private static String TAG = "DeliverFragment";
public DeliverFragment() {
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG, "onCreateView: ");
View view = inflater.inflate(R.layout.blink_fragment_deliver, container, false);
setUI();
return view;
}
private void setUI(){
if(TokenPool.getTokenPool().isLogin()){
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.deliver_frame,new DeliverLoginFragment());
fragmentTransaction.commit();
}else{
FragmentManager fragmentManager = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.deliver_frame,new LoginFragment());
fragmentTransaction.commit();
}
}
@Override
public void onResume() {
setUI();
super.onResume();
Log.d(TAG, "onResume: ");
}
}
我的主要逻辑:在每次setUI时都依靠TokenPool.getTokenPool().isLogin()判断是否登陆,然后使用FragmentTransaction加载不同的fragment
我的问题:每当我退回桌面再打开app时,我的DeliverFragment就有几率为空白页,我之前查了一下好像说在onResume()里面不建议setUI(),我不知道是不是这个问题导致空白页出现。如果是的话,怎么实现在onResume以后依靠用户不同登陆状态加载不同的fragment