Page 195: Downside to direct retrival


#1

In this section we are to start using Bundles and start using arguments part of newInstance method but I am still not clear on how this new method will allow CrimeFragment to be started by host activity which does not have EXTRA_CRIME_ID part of its intent. I mean that was the point of this section. If I remove below code from the CrimeListFragement.java then at run time when I click on the list the app crashes. This is because in the call to CrimeActivity.java you are retrieving EXTRA_CRIME_ID and same is used in newInstance() method. So, this is not clear why with this new Bundle and newInsance() way makes CrimeFragment independent. Can someone please explain?

public void onListItemClick(ListView l, View v, int position, long id){

Crime c = ((CrimeAdapter)getListAdapter()).getItem(position);
//Log.d(TAG, c.getTitle() + " was clicked");
Intent i = new Intent(getActivity(), CrimeActivity.class);
[color=#BF4000]i.putExtra(CrimeFragment.EXTRA_CRIME_ID, c.getID());[/color]
startActivity(i);
}


#2

Once you work through chapter 11 the advantage of fragment arguments will be clearer.