6.6. MainActivity Subclass of Activity

Class MainActivity (Fig. 6.5) is host for the Cannon Game app’s CannonGameFragment. In this app, we override only Activity method onCreate, which inflates the GUI.

 1   // MainActivity.java 2   // MainActivity displays the CannonGameFragment 3   package com.deitel.cannongame; 4  5   import android.app.Activity; 6   import android.os.Bundle; 7  8   public class MainActivity extends Activity 9   {10      // called when the app first launches11      @Override12      public void onCreate(Bundle savedInstanceState)13      {14         super.onCreate(savedInstanceState); // call super's onCreate method15         setContentView(R.layout.activity_main); // inflate the layout16      } ...

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.