The responsibilities of Activity class management are greatly simplified when

The responsibilities of activity class management are

This preview shows page 7 - 12 out of 55 pages.

The responsibilities of Activity class management are greatly simplified when the entire user interface state is moved off into individual fragments. Activity classes with only fragments in their layouts no longer need to spend a lot of time saving and restoring their state because the Activity object now keeps track of any Fragment that is currently attached automatically. The Fragment components themselves keep track of their own state using their own lifecycle. Naturally, you can mix fragments with View controls directly in an Activity class. The Activity class will be responsible for managing the View controls, as normal.
Image of page 7

Subscribe to view the full document.

Understanding the Fragment Lifecycle (Cont’d) Instead, the Activity must focus on managing its Fragment classes. Coordination between an Activity and its Fragment components is facilitated by the FragmentManager: android.app.FragmentManager The FragmentManager is acquired from the getFragmentManager() method, which is available within the Activity and Fragment classes. When using the support library, coordination is facilitated by the FragmentManager from android.support.v4.app.FragmentManager and is acquired from the getSupportFragmentManager() method of the FragmentActivity support APIs.
Image of page 8