This imports an package,which define the Activity class.You can find the source file in "your ADT directory"\sdk\sources\android-22\android\app package com.example.editgreeting; import android.app.Activity; public class MainActivity extends Activity @Override protected void onCreate(Bundle savedInstancestate){ super.onCreate(savedInstanceState); setContentview(R.layout.activity_main); 16
16 This imports an package, which define the Activity class. You can find the source file in “your ADT directory” \sdk\sources\android-22\android\app
This defines a package,and include your MainActivity class in the package. This imports an package,which define the Activity class.You can Can you roughly guess the directory of find the source file in "your ADT your MainActivity.java file based on the directory"\sdk\sources\android- package name? 22\android\app package com.example.editgreeting; import android.app.Activity; public class MainActivity extends Activity @Override protected void onCreate(Bundle savedInstancestate){ super.onCreate(savedInstancestate); setContentview(R.layout.activity_main); Declare a class 17
17 This defines a package, and include your MainActivity class in the package. Can you roughly guess the directory of your MainActivity.java file based on the package name? This imports an package, which define the Activity class. You can find the source file in “your ADT directory” \sdk\sources\android- 22\android\app Declare a class
This defines a package,and include your MainActivity class in the package. This imports an package,which define the Activity class.You can Can you roughly guess the directory of find the source file in "your ADT your MainActivity.java file based on the directory"\sdk\sources\android- package name? 22\android\app package com.example.editgreeting; import android.app.Activity; public class MainActivity extends Activity @overri de protected void onCreate(Eundle savedInstanceState){ super.onCreate(savedinstancestate); setcontentview(R.layput.activity_main); Declare Declare the a class inheritance 6
18 This defines a package, and include your MainActivity class in the package. Can you roughly guess the directory of your MainActivity.java file based on the package name? Declare a class Declare the inheritance This imports an package, which define the Activity class. You can find the source file in “your ADT directory” \sdk\sources\android- 22\android\app
This defines a package,and include your MainActivity class in the package. This imports an package,which define the Activity class.You can Can you roughly guess the directory of find the source file in "your ADT your MainActivity.java file based on the directory"\sdk\sources\android- package name? 22\android\app package com.example.editgreeting; import android.app.Activity; public class MainActivity extends Activity protedted void onCreate(Eundle savedInstancestate){ super.onCreate(savedinstancestate); setContentview(R.layput.activity]main); Declare Declare the Specify the a class inheritance superclass 19
19 This defines a package, and include your MainActivity class in the package. Can you roughly guess the directory of your MainActivity.java file based on the package name? Declare a class Declare the inheritance Specify the superclass This imports an package, which define the Activity class. You can find the source file in “your ADT directory” \sdk\sources\android- 22\android\app
Java use the @Override annotation to indicate that the method is created by overriding. When we use this annotation for a method,it tells compiler that we are trying to override a superclass method,and enable the compiler to double check it for us if the method is indeed defined in the superclass. http://ww.journaldev.com/817/overriding-methods-in- java-always-use-override-annotation package com.example editgreeting; import android.app.Activity; public class MainActivity extends Activity @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentview(R.layout.activity_main); You can consider the onCreate Adopt the activity main.xml method to be the entry point which is as the layout called first by the system in an app. http://developer.android.com/reference/android/app/Activity.html 20
20 Java use the @Override annotation to indicate that the method is created by overriding. When we use this annotation for a method, it tells compiler that we are trying to override a superclass method, and enable the compiler to double check it for us if the method is indeed defined in the superclass. You can consider the onCreate method to be the entry point which is called first by the system in an app. Adopt the activity_main.xml as the layout http://developer.android.com/reference/android/app/Activity.html http://www.journaldev.com/817/overriding-methods-injava-always-use-override-annotation