Coding the fragment communications in MainActivity

We just need to implement the ActivityComs interface and add an instance of our DataManager class. Then, we'll handle the two methods of the interface, and we are good to go.

Implement the interface and add an instance of DataManager as shown highlighted in the next code:

public class MainActivity extends ActionBarActivity implements ActivityComs{

    private ListView mNavDrawerList;
    private DrawerLayout mDrawerLayout;
    private ArrayAdapter<String> mAdapter;
    private ActionBarDrawerToggle mDrawerToggle;
    private String mActivityTitle;

    public DataManager dataManager;

Initialize the DataManager instance by adding the highlighted line of code in onCreate:

@Override protected void onCreate(Bundle savedInstanceState) ...

Get Android Programming for Beginners 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.