publicvoidstartActivityForResult(Intentintent,intrequestCode){if(requestCode!=-1&&(requestCode&0xffff0000)!=0){thrownewIllegalArgumentException("Can only use lower 16 bits for requestCode");}super.startActivityForResult(intent,requestCode);}
/** * Called by Fragment.startActivityForResult() to implement its behavior. */publicvoidstartActivityFromFragment(Fragmentfragment,Intentintent,intrequestCode){if(requestCode==-1){super.startActivityForResult(intent,-1);return;}if((requestCode&0xffff0000)!=0){thrownewIllegalArgumentException("Can only use lower 16 bits for requestCode");}super.startActivityForResult(intent,((fragment.mIndex+1)<<16)+(requestCode&0xffff));}
/** * Dispatch incoming result to the correct fragment. */@OverrideprotectedvoidonActivityResult(intrequestCode,intresultCode,Intentdata){mFragments.noteStateNotSaved();intindex=requestCode>>16;if(index!=0){index--;if(mFragments.mActive==null||index<0||index>=mFragments.mActive.size()){Log.w(TAG,"Activity result fragment index out of range: 0x"+Integer.toHexString(requestCode));return;}Fragmentfrag=mFragments.mActive.get(index);if(frag==null){Log.w(TAG,"Activity result no fragment exists for index: 0x"+Integer.toHexString(requestCode));}else{frag.onActivityResult(requestCode&0xffff,resultCode,data);}return;}super.onActivityResult(requestCode,resultCode,data);}