onActivityResult is not being called in Fragment

后端 未结 30 2604
忘了有多久
忘了有多久 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 04:56

    1. You can simply override BaseActivity onActivityResult on fragment baseActivity.startActivityForResult .

    2. On BaseActivity add interface and override onActivityResult.

      private OnBaseActivityResult baseActivityResult;
      public static final int BASE_RESULT_RCODE = 111;
      public interface OnBaseActivityResult{
          void onBaseActivityResult(int requestCode, int resultCode, Intent data);
         }
      }
      
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if(getBaseActivityResult() !=null && requestCode == BASE_RESULT_RCODE){
          getBaseActivityResult().onBaseActivityResult(requestCode, resultCode, data);
          setBaseActivityResult(null);
      }
      
    3. On Fragment implements OnBaseActivityResult

      @Override
      public void onBaseActivityResult(int requestCode, int resultCode, Intent data) {
      Log.d("RQ","OnBaseActivityResult");
      if (data != null) {
          Log.d("RQ","OnBaseActivityResult + Data");
          Bundle arguments = data.getExtras();
        }
      }
      

    This workaround will do the trick.

提交回复
热议问题