回调异常解决办法:
public class MyBaseFragmentActivity extends FragmentActivity
{
private String TAG="MyBaseFragmentActivity";
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
FragmentManager fragmentManager=getSupportFragmentManager();
for(int indext=0;indext<fragmentManager.getFragments().size();indext++)
{
Fragment fragment=fragmentManager.getFragments().get(indext); //找到第一层Fragment
if(fragment==null)
Log.w(TAG, "Activity result no fragment exists for index: 0x"
+ Integer.toHexString(requestCode));
else
handleResult(fragment,requestCode,resultCode,data);
}
}
/**
* 递归调用,对所有的子Fragment生效
* @param fragment
* @param requestCode
* @param resultCode
* @param data
*/
private void handleResult(Fragment fragment,int requestCode,int resultCode,Intent data)
{
fragment.onActivityResult(requestCode, resultCode, data);//调用每个Fragment的onActivityResult
Log.e(TAG, "MyBaseFragmentActivity");
List<Fragment> childFragment = fragment.getChildFragmentManager().getFragments(); //找到第二层Fragment
if(childFragment!=null)
for(Fragment f:childFragment)
if(f!=null)
{
handleResult(f, requestCode, resultCode, data);
}
if(childFragment==null)
Log.e(TAG, "MyBaseFragmentActivity1111");
}
}