publicvoidstartActivity(Intent intent){ if (mHost == null) { thrownew IllegalStateException("Fragment " + this + " not attached to Activity"); } mHost.onStartActivityFromFragment(this/*fragment*/, intent, -1); }
publicvoidstartActivityForResult(Intent intent, int requestCode){ if (mHost == null) { thrownew IllegalStateException("Fragment " + this + " not attached to Activity"); } mHost.onStartActivityFromFragment(this/*fragment*/, intent, requestCode); }
/** * Dispatch incoming result to the correct fragment. */ @Override protectedvoidonActivityResult(int requestCode, int resultCode, Intent data){ mFragments.noteStateNotSaved(); int index = requestCode >> 16; if (index != 0) { index--; finalint activeFragmentsCount = mFragments.getActiveFragmentsCount(); if (activeFragmentsCount == 0 || index < 0 || index >= activeFragmentsCount) { Log.w(TAG, "Activity result fragment index out of range: 0x" + Integer.toHexString(requestCode)); return; } final List<Fragment> activeFragments = mFragments.getActiveFragments(new ArrayList<Fragment>(activeFragmentsCount)); Fragment frag = activeFragments.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; }
/** * Modifies the standard behavior to allow results to be delivered to fragments. * This imposes a restriction that requestCode be <= 0xffff. */ @Override publicvoidstartActivityForResult(Intent intent, int requestCode){ if (requestCode != -1 && (requestCode & 0xffff0000) != 0) { thrownew IllegalArgumentException("Can only use lower 16 bits for requestCode"); } super.startActivityForResult(intent, requestCode); }
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.