简体   繁体   中英

When fragment is on resume it go back to on create view if condition is true

I want the fragment at on Resume stage to go back to on Create View stage if it meet a specific condition, is that possible.

 public class FragBeamRec extends Fragment {

        public static FragBeamRec newInstance() {
            FragBeamRec fragment = new FragBeamRec();
            return fragment;
               }

        public FragBeamRec() {
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_frag2, container, false);

    globalvar.booIstrue = false;

            return inflater.inflate(R.layout.fragment_frag2, container, false);
        }

    @Override
        public void onResume(){
        super.onResume();

    if (globalvar.booIstrue){
    // what do i write here to make it back to onCreateView
    }
    }
    }

Just move the onCreateView logic into a separate method.that 's the trick. cheers :)

public class FragBeamRec extends Fragment {

 public static FragBeamRec newInstance() {
  FragBeamRec fragment = new FragBeamRec();
  return fragment;
 }

 public FragBeamRec() {}

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
  Bundle savedInstanceState) {
  View rootView = inflater.inflate(R.layout.fragment_frag2, container, false);


  doYourMagicHere();

  return inflater.inflate(R.layout.fragment_frag2, container, false);
 }

 @Override
 public void onResume() {
  super.onResume();


  if (globalvar.booIstrue) {
   // what do i write here to make it back to onCreateView
   doYourMagicHere();
  }
 }
 public void doYourMagicHere() {
  globalvar.booIstrue = false;
 }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM