onActivityResult is not being called in Fragment

后端 未结 30 2605
忘了有多久
忘了有多久 2020-11-21 04:28

The activity hosting this fragment has its onActivityResult called when the camera activity returns.

My fragment starts an activity for a result with th

30条回答
  •  礼貌的吻别
    2020-11-21 05:04

    Most of these answers keep saying that you have to call super.onActivityResult(...) in your host Activity for your Fragment. But that did not seem to be working for me.

    So, in your host Activity you should call your Fragments onActivityResult(...) instead. Here is an example.

    public class HostActivity extends Activity {
    
        private MyFragment myFragment;
    
        protected void onActivityResult(...) {
            super.onActivityResult(...);
            this.myFragment.onActivityResult(...);
        }
    }
    

    At some point in your HostActivity you will need to assign this.myFragment the Fragment you are using. Or, use the FragmentManager to get the Fragment instead of keeping a reference to it in your HostActivity. Also, check for null before you try to call the this.myFragment.onActivityResult(...);.

提交回复
热议问题