1
MOBILE APPLICATION
DEVELOPMENT
05-Jun-23 By:- Yigermal S.
Exam contents
2
Students will be able to describe the basic components of an Android
application.(1)
Students will be able to define the lifecycle methods of Android application
components.(1)
Students will be able to explain the basics of event handling in Android.(2)
Students will be able to express the basics of graphics and multimedia support
in Android.(2)
Students will be able to demonstrate basic skills of using an integrated
development environment (Android Studio) and Android Software
Development Kit (SDK) for implementing simple Android applications.(2)
Basic components of an Android application.(1)
3
Android applications are developed using JAVA,
Kotlin, and C++.
Application components are very essential for
building Applications. They work as an entry point
for users or system to enter your application.
There are four different types of components. Each
component has its own purpose and distinct life
cycle.
The basic components of an Android application
4
are:
1. Activities
An activity is a class that is considered as an entry point
for users that represents a single screen. A messenger
application might have an activity that shows a new
notification, another activity which reads messages and
another which composes a new message.
2. Services
5
A service is a component that runs in the background,
it acts as an invisible worker of our application. It
keeps updating data sources and activities. It
also broadcasts intents and performs tasks when
applications are not active. An example of service is
we can surf the internet or use any other application
while listening to music.
Cont..
6
Each activity is independent of one another. For
example – camera application can be started in an
email application to compose an email that shares an
image. The picture below depicts how each new
activity adds an item to back stack and how the
current activity is destroyed and previous activity is
resumed. We will study the life cycle of activity in
detail in our Android Activity article.
CONT..
7
CONT…
8
When we work on an application what we see is a UI on the screen
which is an activity. Most of the applications that we use have many
activities. Among all those activities, one is the MainActivity() & the
rest are its ChildActivities(). Generally, the first page that appears on
the screen when an application opens is referred to as MainActivity().
This main activity interacts with the child activities and lets the user
access them.
Android Activity Lifecycle
9
An activity can have four states, which are :
1. Running
2. Paused
3. Resumed
4. Stopped
[Link] State
10
An activity is in the running state if it’s shown
in the foreground of the users’ screen. Activity
is in the running state when the user is
interacting with it.
[Link] State
11
When an activity is not in the focus but is still alive
for the user, it’s in a paused state. The activity
comes in this state when some other activity comes
in with a higher position in the window.
[Link] State
12
It is when an activity goes from the paused state
to the foreground that is an active state.
[Link] State
13
When an activity is no longer in the
activity stack and not visible to the users.
Android Activity Methods
14
Android activities go through four states during their
entire lifecycle. These activities have callback
methods() to describe each activity in each of the four
stages. These methods need to be overridden by the
implementing subclass.
In Android, we have the following 7 callback methods
that activity uses to go through the four states:
CONT…
15
1. onCreate()
2. onStart()
3. onPause()
4. onRestart()
5. onResume()
6. onStop()
7. onDestroy()
onCreate()
16
The Android oncreate() method is called at the very start when an
activity is created. An activity is created as soon as an application is
opened. This method is used in order to create an Activity.
2. onStart()
17
The Android onstart() method is invoked as soon as the
activity becomes visible to the users. This method is to start an
activity. The activity comes on the forescreen of the users
when this method is invoked.
3. onPause()
18
The Android onPause() method is invoked when the activity doesn’t
receive any user input and goes on hold. In the pause state, the activity
is partially visible to the user. This is done when the user presses the
back or home buttons. Once an activity is in the pause state, it can be
followed by either onResume() or onStopped() callback method.
4. onRestart()
19
The Android onRestart() method is invoked when activity is about to
start from the stop state. This method is to restart an activity that had
been active some time back. When an activity restarts, it starts
working from where it was paused.
5. onResume()
20
The Android onResume() method is invoked when the user starts
interacting with the user. This callback method is followed
by onPause(). Most of the functionalities of an application are
implemented using onResume().
6. onStop()
21
The Android onDestroy() is the method that is called when an activity
finishes and the user stops using it. It is the final callback method
received by activity, as after this it is destroyed.
7. onDestroy()
22
The Android onDestroy() is the method that is called when an activity
finishes and the user stops using it. It is the final callback method
received by activity, as after this it is destroyed.
CONT…
23
Review questions
24
( A. onCreate() −> onStart() −> onActivityStarted() −> onResume() −> onPause() −> onStop() −> onActivityDistroy() −>
a onDestroy()
)
( B OnCreate() −> onStart() −>onResume() −> onPause() −> onStop() −> onRestart() −> onDestroy()
b
)
( [Link]() −> onStart() −> onPause() −> onResume() −> onStop() −> onDestroy()
c
)
( onResume()
d
)
What is an intent ?
25
It is an inter-application message passing framework for
communication between android components. It is also used
for transferring data between different Activities as well as to
start a new service and display a list of contacts in ListView.
Example – the camera application sends an intent to the
operating system when the user decides to share a picture.
3. Content Providers
26
Content Provider is a component that allows applications to share data
among multiple applications.
It hides the details of the database and can be used to read and write
private data of the application which is not shared. It would be a mess to
access data from other applications without content providers.
For example – you can consider looking for contact details in contact list. Or
You might want photos from the gallery which are also provided by Content
Provider.
4. Broadcast Receiver
27
Broadcast Receiver is a component that responds to
broadcast messages from another application or the
same system. It can also deliver broadcasts to
applications that are not running. For example – notify
the user that the battery is low. Android developers
can use broadcast messages in the application or
outside the normal flow.
Lifecycle methods of Android application
28
components.
nts.(1)
These are: onCreate(),
onStart(), onResume(),
onPause(), onStop(), and
onDestroy().
Reflection
29
How many main components that can be used within an Android
application?
A. 2
B. 3
C. 4
D. 5
Cont..
30
Which component handle background processing associated with an
application?
A. Activities
B. Services
C. Broadcast Receivers
D. Content Providers
Cont.…
31
What is true about Content Providers?
A. They dictate the UI and handle the user interaction to the smart
phone screen
B. They handle background processing associated with an application.
C. They handle communication between Android OS and applications
D. They handle data and database management issues
Cont..
32
What is true about Activities component?
A. An activity represents a single screen with a user interface,in-short
Activity performs actions on the screen.
B. application has more than one activity, then one of them should be
marked as the activity that is presented when the application is
launched.
C. An activity is implemented as a subclass of Activity class
D. All of the above
Cont..
33
Which of the following statement is false about Broadcast Receivers?
A. A broadcast receiver is implemented as a subclass of
ContentProvider class
B. A broadcast receiver is implemented as a subclass of Activity class
C. A broadcast receiver is implemented as a subclass of
BroadcastReceiver class
D. A broadcast receiver is implemented as a subclass of Service class
Answer key
34
1. C
2. B
3. D
4. D
5. C
Summery
35
Android architecture:
Linux Kernel
Native libraries
Android runtime
Application Framework
Applications
Basic building blocks component::
36
Activities
Services
Broadcast receiver
Content provider
Views
Libraries of Android:
37
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
basics of event handling in Android
38
Event handling comes with Event and Handling. The event here is
nothing but an Action. Handling here means managing.
In the whole Android Event Handling, all we do is manage the actions.
These actions are related to the user’s interaction. These Events collect
data about the user’s interaction using interactive components.
Cont..
39
For example, when you click on some button, onClick() is invoked. All
the events in Android are stored in a Queue using First In First Out
(FIFO) scheduling.
Android Event Handling
40
To include the Event Handler in your application, you should know the
following three concepts:
Event Listeners
Event Handlers
Event Listener Registration
Event Listeners
41
An event listener is an interface in the View class of Android. It has a
single callback method. This method will be called when the View that
is registered with the Listener is activated by the user’s action.
Cont.…
42
Event Handlers
43
Event handles are the actual methods that have the action that is to be
taken. After an event has happened and event listeners are registered,
event listeners call Event Handler. These are useful to define some
callback methods.
Event Listener Registration
44
Event Registration is the process in which Event Listeners are registered
with Event Handlers. This is important as Handler will work only after
the Listener fires an Event.
Android Event Listener registration can be done in the following
three ways:
1. The first method to register event listeners is by directly mentioning
them in activity_main.xml.
2. We can also register event listeners by using Activity class that
implements a listener interface.
3. The last method is by using an Anonymous class.
Touch mode
45
While a user interacts with the device they roll the screen over.
Therefore it’s necessary to focus on the items that are actionable. In the
devices with touch functionality, and the user begins interacting with it
then it is not important to give focus on touchable items. This mode of
interaction is “Touch Mode”.
Once a user touches the screen, the device enters in touch mode and
then onwards the actionable icons and buttons are kept on focus like –
navigation button or home button
Handling Focus
46
The framework handles the focus movement according to user input.
Handling the focus includes adding and removing the focus according
to the user input movements. Focus changes with the help of Views. You
can check if the View is set to be in focusable mode or not
using isFocusable(). And we can also change the focus mode by
using setFocusable().
Cont..
47
We can set the focus of view in touch mode as well,
using setFocusInTouchMode(). To check if a view allows focus in touch
mode use isFocusableInTouchMode().
graphics and multimedia support in Android
48
Android provides a huge set of 2D-drawing APIs that allow you to create
graphics.
Android has got visually appealing graphics and mind blowing animations.
The Android framework provides a rich set of powerful APIS for applying
animation to UI elements and graphics as well as drawing custom 2D and
3D graphics.
Cont…
49
Following are the three animation systems used in Android
applications:
1. Property Animation
2. View Animation
3. Drawable Animation
Property Animation
50
Property animation is the preferred method of animation in Android.
This animation is the robust framework which lets you animate any
properties of any objects, view or non-view objects.
The [Link] provides classes which handle property
animation.
View Animation
51
View Animation is also called as Tween Animation.
The [Link] provides classes which handle view
animation.
This animation can be used to animate the content of a view.
It is limited to simple transformation such as moving, re-sizing and
rotation, but not its background color.
Drawable Animation
52
Drawable animation is implemented using the AnimationDrawable class.
This animation works by displaying a running sequence of ‘Drawable’
resources that is images, frame by frame inside a view object.
Canvas
Android graphics provides low level graphics tools such as canvases,
color, filters, points and rectangles which handle drawing to the screen
directly.
The Android framework provides a set of 2D-DRAWING APIs which
allows user to provide own custom graphics onto a canvas or to modify
existing views to customize their look and feel.
Cont…
53
Some of the important methods of Canvas Class are as follows
drawText() drawRoundRect() drawCircle() drawRect() drawBitmap()drawARGB()
You can use these methods in onDraw() method to create your own custom user
interface.
Drawing an animation with a View is the best option to draw simple graphics
that do not need to change dynamically and are not a part of a performance-
intensive game. It is used when user wants to display a static graphic or
predefined animation.
Drawing an animation with a Canvas is better option when your application
needs to re-draw itself regularly. For example video games should be
drawing to the Canvas on its own.
Android Multimedia.
54
Android provides many ways to control playback of audio/video files
and streams. One of this way is through a class called MediaPlayer.
Android is providing MediaPlayer class to access built-in mediaplayer
services like playing audio,video e.t.c. In order to use MediaPlayer, we
have to call a static Method create() of this class. This method returns
an instance of MediaPlayer class. Its syntax is as follows −
Cont..
55
The second parameter is the name of the song that you want to play.
You have to make a new folder under your project with name raw and
place the music file into it.
Once you have created the Mediaplayer object you can call some
methods to start or stop the music. These methods are listed below.
Cont.…
56
On call to start() method, the music will start playing from the
beginning. If this method is called again after the pause() method, the
music would start playing from where it is left and not from the
beginning.
In order to start music from the beginning, you have to
call reset() method. Its syntax is given below.
Cont..
57
Apart from the start and pause method, there are other methods
provided by this class for better dealing with audio/video files.
Android framework to implement multimedia capture and playback.
Cont.…
58
Media Playback
How to play audio and video in your application.
JetPlayer
How to play interactive audio and video in your application using
content created with JetCreator.
Camera
How to use a device camera to take pictures or video in your
application.
Audio Capture How to record sound in your application
59
60
Be the digger of
Live For What You Believe!!!!!!!
End of Chapter Five
61
Question
Comment
Thank you!