0
00:00:00,000 --> 00:00:01,120


1
00:00:01,120 --> 00:00:04,490
Now that we have completed the Hello World application

2
00:00:04,490 --> 00:00:10,920
and seen it running, either on the emulator or on a real device,

3
00:00:10,920 --> 00:00:15,400
let's go ahead and examine this application in a bit more detail

4
00:00:15,400 --> 00:00:19,916
in order to understand some aspects about Android applications.

5
00:00:19,916 --> 00:00:22,710


6
00:00:22,710 --> 00:00:25,500
As we have already realized, Android applications

7
00:00:25,500 --> 00:00:28,070
are all written in the Java programming language.

8
00:00:28,070 --> 00:00:35,020
Android Studio then compiles the Java code along with the data and resources

9
00:00:35,020 --> 00:00:40,560
that you supply for your application, and then prepares a package called

10
00:00:40,560 --> 00:00:44,330
as the .apk package.

11
00:00:44,330 --> 00:00:52,040
This is what you install on a real device or on an emulator.

12
00:00:52,040 --> 00:00:56,430
Of course, when you download applications from the Play Store,

13
00:00:56,430 --> 00:00:58,710
this is automatically done for you.

14
00:00:58,710 --> 00:01:04,510
So essentially, it involves downloading this .apk package and then installing

15
00:01:04,510 --> 00:01:06,350
it on your device.

16
00:01:06,350 --> 00:01:12,650
When you deploy your application from Android Studio, either to the emulator

17
00:01:12,650 --> 00:01:16,800
or to a real device, it is exactly the same process.

18
00:01:16,800 --> 00:01:21,880
The .apk package is pushed onto the device and then installed

19
00:01:21,880 --> 00:01:22,970
on the device.

20
00:01:22,970 --> 00:01:25,602
What does the .apk package actually contain?

21
00:01:25,602 --> 00:01:32,300
It contains the compiled Java classes, which are prepared from the Java code

22
00:01:32,300 --> 00:01:36,530
that you write together with resources and other data files

23
00:01:36,530 --> 00:01:39,690
that you supply for your Android application.

24
00:01:39,690 --> 00:01:42,610
We'll examine the remaining two, the resources and data

25
00:01:42,610 --> 00:01:45,785
files, later on as we go through the course.

26
00:01:45,785 --> 00:01:50,010


27
00:01:50,010 --> 00:01:54,500
Let's now return to Android Studio and examine the Hello World application

28
00:01:54,500 --> 00:01:57,390
in a little more detail.

29
00:01:57,390 --> 00:02:02,400
In Android Studio, you will notice the user interface layout

30
00:02:02,400 --> 00:02:08,620
that you see corresponding to what you see running on the real device.

31
00:02:08,620 --> 00:02:14,210
We'll examine this in a bit more detail in one of the later sections.

32
00:02:14,210 --> 00:02:18,790
Let's switch to the MainActivity.java tab,

33
00:02:18,790 --> 00:02:23,050
and then, have a look at the source code being displayed here.

34
00:02:23,050 --> 00:02:26,560


35
00:02:26,560 --> 00:02:32,630
Let's take a closer look at the Java code in MainActivity.java.

36
00:02:32,630 --> 00:02:35,640
As we examine this code, let me draw your attention

37
00:02:35,640 --> 00:02:38,540
to two sections of the code.

38
00:02:38,540 --> 00:02:44,190
First part, you notice that we are extending a class called

39
00:02:44,190 --> 00:02:46,560
as the Activity class here.

40
00:02:46,560 --> 00:02:49,800
And the second part, you see that we are overriding

41
00:02:49,800 --> 00:02:55,200
certain methods inside this class here.

42
00:02:55,200 --> 00:02:58,540
In particular, let me draw your attention to the fact

43
00:02:58,540 --> 00:03:02,310
that we are overriding a method called onCreate method here.

44
00:03:02,310 --> 00:03:06,870
And we have a few lines of code inside the onCreate method.

45
00:03:06,870 --> 00:03:11,815
The remaining part of the code, we will examine in one of the later exercise.

46
00:03:11,815 --> 00:03:14,920


47
00:03:14,920 --> 00:03:20,910
Now that you have had a closer look at the Java code, let's now go ahead

48
00:03:20,910 --> 00:03:24,970
and examine why we subclass the Activity class

49
00:03:24,970 --> 00:03:30,710
and what exactly is the Activity class that we are subclassing in the code.

50
00:03:30,710 --> 00:03:35,840
To explain it in a bit more detail, a typical Android application

51
00:03:35,840 --> 00:03:42,260
is composed of four basic components, activities, services, broadcast

52
00:03:42,260 --> 00:03:46,470
receivers, and content providers.

53
00:03:46,470 --> 00:03:50,400
Let me briefly summarize the four kind of components that can

54
00:03:50,400 --> 00:03:53,620
form part of an Android application.

55
00:03:53,620 --> 00:03:57,060
Activities are typically dealing with the user interface

56
00:03:57,060 --> 00:03:58,650
part of your application.

57
00:03:58,650 --> 00:04:03,000
Services are primarily used for doing background work on your behalf.

58
00:04:03,000 --> 00:04:07,640
Content providers are dealing with data storage

59
00:04:07,640 --> 00:04:13,530
and exposing the data within your application to the remaining components

60
00:04:13,530 --> 00:04:16,000
or to other applications.

61
00:04:16,000 --> 00:04:21,420
Broadcast receivers are used to deal with any events that need

62
00:04:21,420 --> 00:04:24,760
to be delivered to your application.

63
00:04:24,760 --> 00:04:27,960
This is a broad summary of these four components.

64
00:04:27,960 --> 00:04:32,150
As we go through the course, we will examine some of these in more detail.

65
00:04:32,150 --> 00:04:36,930


66
00:04:36,930 --> 00:04:40,570
Let's, in particular, examine what an activity is.

67
00:04:40,570 --> 00:04:46,590
As I have just emphasized, an activity deals with the user interface aspects

68
00:04:46,590 --> 00:04:48,460
of your Android application.

69
00:04:48,460 --> 00:04:51,800
Every screen that you see within you application

70
00:04:51,800 --> 00:04:56,570
is controlled by an activity behind the scenes.

71
00:04:56,570 --> 00:04:58,720
So how do you create an activity?

72
00:04:58,720 --> 00:05:04,500
You create an activity by extending the Activity base class.

73
00:05:04,500 --> 00:05:12,060
And within this class, you will implement the appropriate code

74
00:05:12,060 --> 00:05:15,000
to create the user interface.

75
00:05:15,000 --> 00:05:20,630
And the activity also deals with providing the ability for users

76
00:05:20,630 --> 00:05:23,150
to interact with your applications.

77
00:05:23,150 --> 00:05:26,590
We'll examine each of these in more detail in some

78
00:05:26,590 --> 00:05:31,720
of the later examples in this course.

79
00:05:31,720 --> 00:05:35,210
Typically, when you launch your Android application,

80
00:05:35,210 --> 00:05:39,510
you click on the icon corresponding to your application.

81
00:05:39,510 --> 00:05:42,970
Now essentially, what happens is that when you click on the icon

82
00:05:42,970 --> 00:05:48,410
this results in a call into the Android framework, which

83
00:05:48,410 --> 00:05:54,420
then goes ahead and creates the appropriate activity that

84
00:05:54,420 --> 00:05:57,165
displays the user interface for your application.

85
00:05:57,165 --> 00:06:00,000


86
00:06:00,000 --> 00:06:04,480
Creating the activity involves the Android framework

87
00:06:04,480 --> 00:06:12,770
calling the onCreate method that you implement within your Activity class.

88
00:06:12,770 --> 00:06:18,160
Hence, the reason you see the onCreate method in the code

89
00:06:18,160 --> 00:06:20,080
that we just examined a bit earlier.

90
00:06:20,080 --> 00:06:22,890


91
00:06:22,890 --> 00:06:27,760
Returning to the code again, you notice that, within the onCreate method,

92
00:06:27,760 --> 00:06:33,850
we are calling two different methods here again.

93
00:06:33,850 --> 00:06:37,830
The first one is a call to the super class.

94
00:06:37,830 --> 00:06:40,260
And you're passing a Bundle there.

95
00:06:40,260 --> 00:06:42,100
Don't worry about what it is at this moment.

96
00:06:42,100 --> 00:06:44,490
We'll come to that in a later part.

97
00:06:44,490 --> 00:06:48,677
The second statement that you see here is setContentView.

98
00:06:48,677 --> 00:06:51,510
And then, you are supplying something called R.layout.activity_main.

99
00:06:51,510 --> 00:06:56,100


100
00:06:56,100 --> 00:07:02,100
This parameter supplies the layout of the user

101
00:07:02,100 --> 00:07:04,600
interface for your application.

102
00:07:04,600 --> 00:07:09,210
And so when the activity gets created, this particular layout

103
00:07:09,210 --> 00:07:15,630
will be put on the device's user interface.

104
00:07:15,630 --> 00:07:21,070
That is the reason why you see the user interface being

105
00:07:21,070 --> 00:07:25,760
defined in another file called as the layout file.

106
00:07:25,760 --> 00:07:31,095
We will examine layout files in more detail in the following example.

107
00:07:31,095 --> 00:07:33,780


108
00:07:33,780 --> 00:07:38,910
Not that we have a basic understanding of an Android application,

109
00:07:38,910 --> 00:07:41,415
let's now go to the next example where we

110
00:07:41,415 --> 00:07:47,530
will look at user interface widgets, layouts, and event listeners

111
00:07:47,530 --> 00:07:49,610
in more detail.


