8.5. MainActivity Class

Class MainActivity (Figs. 8.148.23) manages the app’s fragments and coordinates the interactions between them. On phones, MainActivity displays one Fragment at a time, starting with the ContactListFragment. On tablets, MainActivity always displays the ContactListFragment at the left of the layout and, depending on the context, displays either the DetailsFragment or the AddEditFragment in the right two-thirds of the layout.

 1   // MainActivity.java 2   // Hosts Address Book app's fragments 3   package com.deitel.addressbook; 4  5   import android.app.Activity; 6   import android.app.FragmentTransaction; 7   import android.os.Bundle; 8  9   public class MainActivity extends Activity10       ...

Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.