CCNPO DevTeam
Today’s Manifest
● An app has several interfaces to interact with
the Android system.
● Basic building blocks we’d discusso Activity
o Context
o Intent
o Service
o Broadcast and BroadcastReceiver
o Storage
CCNPO DevTeam
Activity
● Application component which interacts with
the user
● Interaction happens via the Android UIo i.e. the screen
● An app usually starts with a default Activity
● It can ask Android to start new Activities
http://developer.android.com/guide/components/activities.html
CCNPO DevTeam
Context
● The interface to the environment of the
application.
● Allows access to resourceso R’s resources, System resources (e.g. Content
providers)
● Allows calling new activitieso new Activities, Services
● Brings in new requestso Broadcasts
CCNPO DevTeam
Intent
● A messaging object which can be used to
request action from another application
component
● Can be used too Start Activity
o Start Service
o Deliver a broadcast
CCNPO DevTeam
Intent
● Two typeso Explicit
o Implicit
● Contains >>
Intent
Component Name
Action
Data
Category
Extras
Flags
CCNPO DevTeam
Explicit Intent
● Specifies which component to use / starto Starting new Activity in the app
o Starting new Service
Intent mainShowIntent = new Intent(
getApplicationContext(), ScreenMain.class);
startActivity(mainShowIntent);
CCNPO DevTeam
Implicit Intent
● Declares a general action
to performo Send SMS, email
o Share something
● When the intent is
delivered to Android
System, it either decides
which app to use, or asks
the user if there are
multiple
CCNPO DevTeam
Service
● Application component which runs in the
background
● Continues to run even if the user switches to
another app.
● Can be started from an Activity using an
Intent
What do you
mean what are
they?
I just told you!
CCNPO DevTeam
Broadcast
● System-wide message sent to apps
● Broadcast contains an Intent and a Context
it was fired.
● Two types
o Un-Ordered (Normal)
o Ordered
CCNPO DevTeam
Broadcast Receiver
● Listens to a broadcast
● The broadcast can be triggered by the
system, another app and the same app.
● Application can opt-in to listen using an
Intent Filter specified in;o Manifest entry
o By creating a runtime object
CCNPO DevTeam
Storage
● Google lists the following storage optionso Internal Storage
o External Storage
o Shared Preferences
o Database
o Network
CCNPO DevTeam
Storage - Internal Storage
● Private to the application
● Read / Write as a File
● Stored in a safe app-limited location
● Deleted when the app is uninstalled
CCNPO DevTeam
Storage - External Storage
● Stores data on the external disk
● Can be SD card / USB
● Use with care. The user could
o Un-mount the volume
o Connect the card to a PC
Which would make this unavailable for
app’s usage
CCNPO DevTeam
Storage - Shared Preferences
● App-limited data space
● Uses key-value pairs
● Only primitive data types can be stored
● Great for small persistent values in app
Note: Settings has a separate set of functions to make
things easy. Don’t manually store user’s preferences
CCNPO DevTeam
Storage - Database
● Android comes with a sqlite database
● Apps have their own databases
● Simple queries can be executed
CCNPO DevTeam
Storage - Network
● Use the internet / Wifi to send data to a
server
● How? Anyway you like
o JSON
o XML
o HTTP GET, POST
o or whatever method you want… just decide…
CCNPO DevTeam
Code Demo
Simple app to:
● Record the battery level every 10s
● View the current level
● View recorded values
● Share recorded values
CCNPO DevTeam
Stage 1
● Setup the Main Activity
● Setup the Serviceo Code the required startup and looping in the service
o Code the broadcast to send
● Start the service from the activity
● Register for broadcasts from the service
● See the initial results
CCNPO DevTeam
Stage 2
● Setup a BroadcastReceiver and add it in the
manifest
● Use that class to record the samples
● Create an additional Activity to view samples
CCNPO DevTeam
Stage 3
● Configure a share menu item
● Share using intents
CCNPO DevTeam
Finalized Code
Code is available at
https://github.com/tdevinda/DialogAndroidIntro_2.git
Thanks for your participation!