Section 9.11 Implement CrimeListActivity


#1

I’m not fully understand this section. Before we set fragment managment in onCreate of the activity, now we just return the fragment itself, I know we are using the SingleFragmentActivity but I don’t get the big picture .

Can anyone explain me?

  public class CrimeListActivity extends SingleFragmentActivity {
    @Override
    protected Fragment createFragment() {
          return new CrimeListFragment();
                       }
  }

#2

CrimeListActivity extends SingleFragmentActivity.

CrimeListActivity does not override onCreate(). Therefore, when Android calls onCreate() on CrimeListActivity, it’s handled by SingleFragmentActivity.

in SingleFragmentActivity.onCreate(), you’ll find the FragmentManager interaction that you are expecting. You’ll also find a call to createFragment(), the abstract method that you are required to implement in CrimeListActivity. (If you don’t, the app won’t build.) createFragment() returns the fragment that is added to the FragmentManager.


#3

Thank you very much!

[quote=“embeddedmatt”]CrimeListActivity extends SingleFragmentActivity.

CrimeListActivity does not override onCreate(). Therefore, when Android calls onCreate() on CrimeListActivity, it’s handled by SingleFragmentActivity.

in SingleFragmentActivity.onCreate(), you’ll find the FragmentManager interaction that you are expecting. You’ll also find a call to createFragment(), the abstract method that you are required to implement in CrimeListActivity. (If you don’t, the app won’t build.) createFragment() returns the fragment that is added to the FragmentManager.[/quote]