首页 新闻 会员 周边 捐助

android开发 关于在同一个fragment中加载不同页面的问题

0
悬赏园豆:20 [已关闭问题] 关闭于 2020-05-29 00:02
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

Therp-GY的主页 Therp-GY | 初学一级 | 园豆:177
提问于:2020-04-29 16:58
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册