Now that we have completed the Hello World application
and seen it running, either on the emulator or on a real device,
let's go ahead and examine this application in a bit more detail
in order to understand some aspects about Android applications.
As we have already realized, Android applications
are all written in the Java programming language.
Android Studio then compiles the Java code along with the data and resources
that you supply for your application, and then prepares a package called
as the .apk package.
This is what you install on a real device or on an emulator.
Of course, when you download applications from the Play Store,
this is automatically done for you.
So essentially, it involves downloading this .apk package and then installing
it on your device.
When you deploy your application from Android Studio, either to the emulator
or to a real device, it is exactly the same process.
The .apk package is pushed onto the device and then installed
on the device.
What does the .apk package actually contain?
It contains the compiled Java classes, which are prepared from the Java code
that you write together with resources and other data files
that you supply for your Android application.
We'll examine the remaining two, the resources and data
files, later on as we go through the course.
Let's now return to Android Studio and examine the Hello World application
in a little more detail.
In Android Studio, you will notice the user interface layout
that you see corresponding to what you see running on the real device.
We'll examine this in a bit more detail in one of the later sections.
Let's switch to the MainActivity.java tab,
and then, have a look at the source code being displayed here.
Let's take a closer look at the Java code in MainActivity.java.
As we examine this code, let me draw your attention
to two sections of the code.
First part, you notice that we are extending a class called
as the Activity class here.
And the second part, you see that we are overriding
certain methods inside this class here.
In particular, let me draw your attention to the fact
that we are overriding a method called onCreate method here.
And we have a few lines of code inside the onCreate method.
The remaining part of the code, we will examine in one of the later exercise.
Now that you have had a closer look at the Java code, let's now go ahead
and examine why we subclass the Activity class
and what exactly is the Activity class that we are subclassing in the code.
To explain it in a bit more detail, a typical Android application
is composed of four basic components, activities, services, broadcast
receivers, and content providers.
Let me briefly summarize the four kind of components that can
form part of an Android application.
Activities are typically dealing with the user interface
part of your application.
Services are primarily used for doing background work on your behalf.
Content providers are dealing with data storage
and exposing the data within your application to the remaining components
or to other applications.
Broadcast receivers are used to deal with any events that need
to be delivered to your application.
This is a broad summary of these four components.
As we go through the course, we will examine some of these in more detail.
Let's, in particular, examine what an activity is.
As I have just emphasized, an activity deals with the user interface aspects
of your Android application.
Every screen that you see within you application
is controlled by an activity behind the scenes.
So how do you create an activity?
You create an activity by extending the Activity base class.
And within this class, you will implement the appropriate code
to create the user interface.
And the activity also deals with providing the ability for users
to interact with your applications.
We'll examine each of these in more detail in some
of the later examples in this course.
Typically, when you launch your Android application,
you click on the icon corresponding to your application.
Now essentially, what happens is that when you click on the icon
this results in a call into the Android framework, which
then goes ahead and creates the appropriate activity that
displays the user interface for your application.
Creating the activity involves the Android framework
calling the onCreate method that you implement within your Activity class.
Hence, the reason you see the onCreate method in the code
that we just examined a bit earlier.
Returning to the code again, you notice that, within the onCreate method,
we are calling two different methods here again.
The first one is a call to the super class.
And you're passing a Bundle there.
Don't worry about what it is at this moment.
We'll come to that in a later part.
The second statement that you see here is setContentView.
And then, you are supplying something called R.layout.activity_main.
This parameter supplies the layout of the user
interface for your application.
And so when the activity gets created, this particular layout
will be put on the device's user interface.
That is the reason why you see the user interface being
defined in another file called as the layout file.
We will examine layout files in more detail in the following example.
Not that we have a basic understanding of an Android application,
let's now go to the next example where we
will look at user interface widgets, layouts, and event listeners
in more detail.