I'm starting an Activity through the usual means:
Intent startIntent = new Intent(this, DualPaneActivity.class);
startIntent.putExtras(((SearchPageFragment) currentFragment).getPageState());
startActivity(startIntent);
When this activity loads, it places a Fragment in a frame like so:
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
Fragment currentFragment = fragment;
currentFragment.setArguments(getIntent().getExtras());
transaction.replace(R.id.singlePane, currentFragment);
transaction.commit();
Seems simple, right?
However, you can inside of onCreateView() method access three separate bundles (four, if you include the one included in the Fragment's onCreate(Bundle savedInstanceState)
):
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
// Fill state information
Bundle bundle;
if(savedInstanceState != null) bundle = savedInstanceState; // 1
else if(getArguments() != null) bundle = getArguments(); // 2
else bundle = getActivity().getIntent().getExtras(); // 3
setPageState(bundle);
}
In the above instance, I've worked out from trial and error that the bundle I want is the second one, the one retrieved from getArguments()
.
From my understanding the third one from getActivity().getIntent().getExtras();
is actually calling the Bundle from the intent used to start containing activity. I also know from experimentation that savedInstanceState
seems to always be null. But where is it coming from and why is it null?
The documentation says this:
savedInstanceState If non-null, this fragment is being re-constructed from a previous saved state as given here.
That doesn't help me - It's bugging me more than stopping me from moving on. Can someone help me out with this annoyance?