Professional Documents
Culture Documents
(8 credits)
Lecture :
Instructor : Dr. Kennedy Wednesday 07:00 – 09:00
E-mail: kenfactz@gmail.com Room: D01 (LUHANGA HALL)
Practical:
Friday 14:00 – 16:00
1
Lecture 3:
Android Application Overview
2
What Makes Up an Android Project
1: Activities
⚫ Represents a single screen with a user interface
➢ An Activity is where we put together things that the user can see. For
example, an Activity can be made so a user can view a single email or
maybe fill up a form.
⚫ In Figure 1 inside the Activity, there are Views and Fragments.
➢ Views are classes that draw content to the screen; some examples of
View objects are Buttons and TextViews.
➢ A Fragment is similar to an Activity in a way that it’s also a composition
unit but a smaller one. Like Activities, they also hold View objects.
⚫ Activity acts as the ‘controller’ for everything the user sees on its
associated screen
⚫ It is implemented as a subclass of Activity class
Android App Components
2: Services
⚫ A component that runs in the background to perform long-running
operations or to perform work for remote processes
⚫ Does not provide a user interface
⚫ With Services, we can run program logic behind the scenes, without
freezing the user interface.
⚫ Services run in the background.
⚫ They can be very useful when your app is supposed to download a
file from the Web or maybe play music in background.
⚫ Can be started by an activity
⚫ It is implemented as a subclass of Service.
Android App Components
3: BroadcastReceivers
⚫ A component that responds to system-wide broadcast
announcements
⚫ With BroadcastReceivers, app can listen to messages from other
applications or from the Android Runtime itself i.e. android system
⚫ It is implemented as a subclass of BroadcastReceiver and each
broadcast is delivered as an Intent
⚫ A sample use case for this might
➢ Battery low (system) - if you want to display a warning message
when the battery dips to below 10%.
➢ New email (app via notification)
Android App Components
4: ContentProviders
⚫ Lets you write apps that can share data to other apps without
exposing the underbellies of your apps’ SQL structure
⚫ The details of database access are completely hidden from other
apps
⚫ It manages access to some sort of central data repository
⚫ Can store the data in the file system, an SQLite database, on the
web, or any other persistent storage location your app can access
⚫ Through the content provider, other apps can query or even modify
the data
⚫ An example of a prebuilt application that is a ContentProvider is the
“Contacts” app in Android.
➢ Users Contacts (your app could update contact details)
Android App Components
Resources
⚫ Your application may need some visual or audio assets; these are
the kinds of things we mean by “Resources” in Figure 1.
AndroidManifest
⚫ It is a manifest and it’s written in XML.
⚫ It declares quite a few things about the application
1) The name of the app.
2) Which Activity will show up first when the user launches the app.
3) What kind of components are in the app.
❖ If it has activities, the manifest declares them - names of classes
and all.
❖ If the app has services, their class names will also be declared in
manifest.
Android App Components
⚫ If the application has more than one Activity, there will be several
activity nodes in the manifest file, one node for each Activity
Application Entry Point
⚫ When the Android Runtime launches the app, it calls the onCreate()
method of the main Activity which brings the state of the Activity to
“created.”
➢ You can use this method to perform initialization routines like
preparing event handling codes and so on.
⚫ The Activity proceeds to the next state which is “started”; the Activity
is visible to the user at this point, but it’s not yet ready for interaction.
⚫ The next state is “resumed”; this is the state where the app is
interacting with the user.
➢ If the user clicks anything that takes the focus away from the
Activity (answering a phone call or launching another app), the
runtime pauses the current Activity and it enters the “paused”
state.
Activities
➢ From there, if the user goes back to the Activity, the onResume()
function is called, and the Activity runs again.
➢ On the other hand, if the user decides to open a different
application, the Android Runtime may “stop” and eventually
“destroy” the application.
Intents