Android在Fragment中不调用onActivityResult()的解决办法

将Activity继承这个BaseFragmentActivity

解决办法就是,将你出问题的Fragment所在的Activity,来继承这个FragmentActivity,重写onActivityResult(),即可。

/**
 *  让子activity继承这个activity,Fragment去调用startActivityForResult,也可以收到onActivityResult
 *  Created by can on 2017/12/15.
 */
public class MyBaseFragmentActivity extends FragmentActivity {

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        //获取Fragment管理类
        FragmentManager manager=getSupportFragmentManager();
        //遍历Fragments
        for(int i=0;i childFragment = fragment.getChildFragmentManager().getFragments(); 
        if(childFragment!=null)
            for(Fragment f:childFragment)
                if(f!=null)
                    callActivityResult(f, requestCode, resultCode, data);
    }

}


你可能感兴趣的:(android)