Fragment onActivityResult method on executing calls activity onActivityResult

前端 未结 5 1354
余生分开走
余生分开走 2021-02-09 17:57

In my fragment I have started startActivityforresult intent for photo capture.I have overridden onActivityResult callback method in fragment class. I have implemented onActivity

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-09 18:21

    I aslo face this problem.

    Calling of an activity from fragment

    ((Activity)context).startActivityForResult(photoPickerIntent, 100);

    here "context" from FragmentActivity. Now the result comes in FargmentActivity onActivityResult method. to switch this result you have to declare a static variable of fragment class in fragmetn activity class.

    static ActivityUploadPhotos activityUploadPhotos;
    
    ...
    ActivityUploadPhotos f = new ActivityUploadPhotos();
    ActivityHome.activityUploadPhotos=f;
    ......
    
    if(activityUploadPhotos!=null)
    {
               activityUploadPhotos.onActivityResult(requestCode, resultCode, data);
    }
    

提交回复
热议问题