Mobile application development
Exit Exam Tutorial
Contents
The Android Life cycle methods
Basic Components
Platform of basic components
Additional Event handling in Graphics and
Components Android Multimedia
Android studio
Sample questions
environment
The Android Platform
• Android is an open source and Linux-based
Operating System for mobile devices such as
smartphones and tablet computers.
• Android was developed by the Open Handset
Alliance (OHA), led by Google, and other
companies, in 2008.
• Android includes a Linux kernel-based OS, a rich
UI, end-user applications, code libraries,
application frameworks, multimedia support, and
much more.
The Android stack
Basic Android Components
Activity
• Responsible for managing the user
interface (UI) and handling user
interactions
• Extend the Activity
or AppCompatActivity super class to
create activity
Thi s Photo by Unknown author is licensed under CC BY-SA.
Key points in Android Activity
setContentView() method
• It is used to set the user interface (UI) of an Activity
• It should only be called once in the `onCreate()` method of an Activity
• It is used to inflate a layout file and add UI components to the Activity's
view hierarchy
• Takes a layout resource ID as its parameter, which is the ID of the XML
layout file that defines the UI components of the Activity
Role of savedInstanceState() method
• The purpose of this method is to save the current state of the Activity's UI
and data so that it can be restored when the Activity is recreated
• It is a callback method that is called by the system when
• An Activity is about to be destroyed due to a configuration change, such as a screen
rotation or the user changing the device's language
• Passes in a `Bundle` object as a parameter
• used to store key-value pairs that represent the state of the Activity's UI and data
• Used to save user progress and prevent data loss
startActivity() vs startActivityForResult()
startActivity() startActivityForResult()
• used to launch a new activity from an • used to launch a new activity from an
existing activity, without expecting existing activity, with the expectation
any result from the launched activity of getting a result back from the
launched activity.
• allowing it to handle the result
Services
• Used to perform some long-running
operations in the background without
the need to provide UI.
• Can be categorized as :
o Started service (startService)
o Bound service (bindService)
• Created by extending Service or
IntentService classes
Broadcast Receiver
Broadcast Receiver
Are components that enable the system to They are used to listen to system-wide events,
deliver events or messages to the application such as the completion of a phone call or the
outside of a regular user interface receipt of a text message
Broadcast Receiver
• It is a dormant component of android
• Doesn’t contain any user interface( no UI)
• Generally implemented to delegate the tasks to services
depending on the type of intent data that’s received
• Needs to be registered in manifest file
• Following are some of the important system wide generated
intents
System wide Intents Description
[Link].BATTERY_LOW Indicates low battery condition on the device
[Link].BOOT_COMPLETED This is broadcast once, after the system has
finished booting
[Link] To perform a call to someone specified by
the data
[Link].DATE_CHANGED The date has changed
[Link] Have the device reboot
[Link].CONNECTIVITY_CHANGE The mobile network or wifi connection is
changed(or reset)
Content Provider
Content Providers
Are components that enable applications to They provide a standard interface to access
share data with other applications. a shared data set, such as a database.
Android Components Life Cycle
Activity
Lifecycle
Activity Lifecycle methods
• onCreate(): called once for initializing the activity and setting up the UI.
• onStart(): called when activity is visible and ready to interact with the
user.
• onResume(): called when activity is in the foreground and has focus.
Usually it is called after getting paused.
• onPause(): invoked when activity loses focus but is still visible to the
user.
Activity Lifecycle methods
• onStop(): activity is no longer visible to the user, due to navigation to
another activity or getting destroyed.
• onRestart(): happens when activity is stopped and then started
again, it might be due to navigating back to the activity
• onDestroy(): happens when activity is destroyed thereby releasing
any resources that were allocated by the activity
Service Lifecycle
Service Lifecycle methods
• onCreate(): responsible for initializing the service and setting up any
resources that are needed.
• onStartCommand(): responsible for performing the task that the
service was created for. This method can also return a value that
specifies how the system should handle the service if it is killed.
• onHandleIntent(): This method is used to add any code you want the
service to do in the background.
• onDestroy(): responsible for releasing any resources that were
allocated by the service.
Broadcast Receiver Lifecycle methods
• onReceive(): This is the only method that is called when a
broadcast event is received by the receiver. This method is
responsible for performing the task that the receiver was
created for.
• onDestroy(): responsible for releasing any resources that
were allocated by the receiver.
Content Provider Lifecycle methods
onCreate(): This is the first method that query(): This method is called when an
is called when the provider is created. application requests data from the
This method is responsible for provider. This method is responsible for
initializing the provider and setting up returning a cursor object that contains
any resources that are needed. the requested data.
insert(): This method is called when an delete(): This method is called when an
application wants to add data to the application wants to delete data from
provider. This method is responsible for the provider. This method is responsible
inserting the data into the provider's for deleting the specified data from the
data set. provider's data set.
Additional Components
• Views : The basic building block for user
interface is a View object which is created
from the View class and
• It occupies a rectangular area on the
screen and is responsible for drawing and
event handling
• View is the base class for widgets, which
are used to create interactive UI
components like buttons, text fields, etc
• It is a piece of an activity which enable
more modular activity design.
• A fragment is a kind of sub-activity
• You create fragments by extending
Fragments Fragment class and
• You can insert a fragment into your activity
layout by declaring the fragment in the
activity's layout file, as a <fragment>
element
Activity vs Fragment
Activity Fragment
• Activity is a single screen with a user • Fragment is a portion of an Activity's
interface that the user can interact with user interface that can be combined with
• Activities are used to define the entry other fragments to create a complete user
point of an application and handle user interface
interactions, such as responding to button • Fragments, are used to modularize the
clicks or menu selections user interface and make it more flexible
• Activity lifecycle is managed by OS and reusable.
• Fragments lifecycle is managed by the
activity hosting it
• can be added, removed, and replaced
dynamically at runtime
Fragments
Android
Intents
It is a messaging object
you can use to request an
action from another app
component.
Types of Intents
• There are two types of Intents,
• Implicit
• rely on intent filters and the Android environment to dispatch the
Intent to the appropriate recipient
• Explicit intents,
• specifies the exact class that will handle the Intent
• Pending-Intents.
• a type of Intent that allows an application to perform an operation on
behalf of another application or at a later time
• An Intent-Filter is a declaration of capability and interest in
offering assistance to those in need.
Intent Filter • It is an expression in an app’s manifest file that specifies the
type of intents that the component would like to receive.
Android UI Layouts
Layout Types
Constraint
Layout
The XML
code
The Java
Code
Android View Identification
• A view object may have a unique ID assigned to it which will
identify the View uniquely within the tree
• The syntax for an ID, inside an XML tag is −
android:id="@+id/title"
• To create an instance of the view object and capture it from the layout,
use the following −
TextView text = (TextView) findViewById([Link]);
Passing data between activities
• Data can be passed using
a) An Intent
b) Bundle
c) Static variable
Intent intent = new Intent(this, [Link]);
[Link]("key", "value");
startActivity(intent);
Event handling in Android
• The reason we develop an app is to provide services to
a user, and in-order to use it, there must be a way for
the user to interact with it.
• For an Android app, interaction typically includes
tapping, pressing, typing, or talking and listening.
• Events are the messages which are generated by
controls such as buttons, checkbox, radio buttons etc.
• Three concepts related to Android
Event handling
o Event Listener is a view object
which listens for an event.
o Event Handler is the method that
Event handles the event.
Handling o Event Listener Registration is a
process, where an Event Handler
concepts gets registered with an Event
Listener.
• Event Handler is called when the Event
Listener fires the event.
Event Handlers & Event Listeners
Event Handlers Event Listeners & Description
onClick() OnClickListener(): This is called when the user either clicks or
touches or focuses upon any widget like button, text, image
etc.
onLongClick() OnLongClickListener(): This is called when the user either clicks
or touches or focuses upon any widget like button, text, image
etc. for some seconds
onFocusChange() OnFocusChangeListener(): This is called when the widget
looses its focus ie. user goes away from the view item.
onKey() OnFocusChangeListener():This is called when the user is
focused on the item and presses or releases a hardware key on
the device.
Event Handlers & Event Listeners
Event Handlers Event Listeners & Description
onTouch() OnTouchListener(): This is called when the user
presses the key, releases the key, or any
movement gesture on the screen.
onMenuItemClick() OnMenuItemClickListener(): This is called when
the user selects a menu item.
onCreateContextMenu() OnFocusChangeListener(): This is called when
the context menu is being built(as the result of
a sustained "long click)
Common ways to Register events
01 02 03
Using an Activity class Using Layout xml
Anonymous Inner implements the file to specify
Class Listener interface. event handler
directly.
Graphics and
Multimedia in Android
2D Graphics
• Android implements complete 2D functions in one
package, named [Link].
• Includes classes like Canvas, Paint , and Path
• The package provides various kinds of graphics
tools, such as
• color filter,
• point,
• line,
• Rectangles etc
2D Graphics
• Canvas
• Used to draw on
• Paint
• Used to add color and styling to the drawing
• Path
• is basically a collection of lines
3D Graphics
• Supports 3D graphics through OpenGL ES
API
• OpenGL is cross platform
• It offers a set of extremely powerful
tools for manipulating and displaying
high-end animated 3D graphics
Android animation
• Android provides three animation systems for
meeting the animation needs of Android apps.
• Property Animation
• It is the preferred method of animation in Android
and complex
• Drawable Animation
• works by displaying a running sequence of "Drawable"
resources, i.e., images, frame by frame, inside a View
object
• View Animation
• It can only be used to animate the content of a View,
and is limited to simple transformation
Android Multimedia
• Multimedia support shifted from OpenCORE to Stagefright by Google
after Android 3
• Most of the media interaction is done by MediaPlayer API, and used
for
• Playing audio
• Playing video
• Capturing media
• Taking pictures ( takePicture() )
• Capturing audio ( MediaRecorder() )
• Recording video( MediaRecorder() )
...cont'd
• Playing audio
MediaPlayer mp;
mp= [Link]([Link], [Link]);
[Link]();
• Playing video
Add a VideoView widget to your xml file ( <VideoView> )
Load the video file ( setVideoPath() )
Attach controllers to it( setMediaController() )
Android studio environment
Thi s Photo by Unknown author is licensed under CC BY-SA-NC.
Mipmap
• Mipmap folder contains the Image
Asset file that can be used in Android
Studio application.
• You can generate the following icon
types like Launcher icons, Action bar
and tab icons, and Notification icons. Thi s Photo by Unknown author is licensed under CC BY-SA.
Drawable
• A Drawable folder contains resource
type file (something that can be
drawn).
• Drawables may take a variety of file like
Bitmap (PNG, JPEG), Nine Patch, Vector
(XML), Shape, Layers, States, Levels, and
Scale.
Sample
Questions
Next
Question 1
• Application alerts that are used to draw the user’s attention to some
app event without stealing focus or interrupting the current activity of
the user are called
A. Intents
B. Widgets
C. Notifications
D. None of the above
Answer :
Question 2
• The small visual application components that you can find on the
home screen of the devices and allow us to create dynamic,
interactive application components for users to embed on their Home
Screen
A. Intents
B. Widgets
C. Notifications
D. Broadcast Recievers
Answer :
• alallow us to create dynamic, interactive application components for users to embed on their Home Screenlowallow us to create dynamic, interactive
application components for users to embed on their Home Screen us to create dynamic, interactive application components for users to embed on
their Home Screen
Question 3
• It is a powerful inter-application message-passing framework.
A. Intents
B. Bundle
C. Notification
D. A and B
Answer :
Question 4
• ____ make our application react to any received Intent thereby
making them perfect for creating event-driven applications.
A. Services
B. Content providers
C. Broadcast Recievers
D. Activities
Answer :
Question 5
• _____ are like invisible workers of our app.
A. Activities
B. Services
C. Broadcast Recievers
D. Content providers
Answer :
Question 6
• _______are said to be the presentation layer of our applications.
A. Services
B. Activities
C. Content Providers
D. Broadcast Recievers
Answer :
Question 7
• Which one of the following is not true about gradle?
A. reads the app’s build configuration file ([Link])
B. downloads and resolves the app’s dependencies
C. compiles the app’s code
D. packs the compiled code and resources into an APK file
E. None of the above
Answer :
Question 8
• It is used to implement dependencies and plugins on top level.
A. Gradle
B. [Link](project)
C. [Link](module)
D. B and C
Answer :
Question 9
• Android app launcher icons are located inside ________.
A. Drawable folder
B. Mipmap folder
C. Layout folder
D. A and B
Answer :
Question 10
• Android has shifted from OpenCORE to _____ library for its
multimedia support
A. OpenCORE
B. MediaPlayer
C. OpenGL ES
D. Stagefright
Answer :
Question 11
• Which one of the following 2D graphics class is used to add color to
android graphics drawing?
A. Canvas
B. Paint
C. Path
D. Style
Answer :
Question 12
• The most complex type of animation type in android is __
A. Property Animation
B. View Animation
C. Drawable animation
D. All of the above
Answer :
Question 13
• Android uses ________ API for 3D graphics.
A. OpenCORE
B. OpenGL ES
C. Canvas
D. A and B
Answer :
Question 14
• The top most layer of the android architecture is ___
A. Linux kernel
B. Applications
C. Application libraries
D. Drivers
Answer :
Question 15
• Which one of the following is the built-in database for android?
A. Firebase
B. Sqlite
C. MySql
D. Access
Answer :
The End
Thank You