终于找到了解决方案,片段无法在onActivityResult()中交换或替换
我们需要将此代码放入Handler
或放入OnResume()
方案:
private boolean change_fragment=false;
OnActivityResult()代码
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { change_fragment=true; }
OnResume()代码
@Override public void onResume() { super.onResume(); if(change_fragment) { change_fragment=false; Fragment fragment = new VirtualListFragment(); FragmentManager fragmentManager = getFragmentManager(); fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit(); } }