ANDROID ARCHITECTURE - CSE Labs User Home Pages

knapsackyarnMobile - Wireless

Dec 14, 2013 (3 years and 9 months ago)

78 views

ANDROID
ARCHITECTURE
SEng
5199-1: Mobile Application Development
Andy Selvig




Anatomy of an Android App


/assets
(utility files)


/gen
(generated code)


/res
(application resources)


/res/
anim

(animations)


/res/colors
(color state lists)


/res/
drawable

(dpi-independent
drawables
, shape files)


/res/
drawable-hdi

(210-230 dpi)


/res/
drawable-ldi

(<150 dpi, not used)


/res/
drawable
-mdi
(160-180 dpi)


/res/
drawable-xhdi

(>250 dpi)


/res/layout
(view layouts)


/res/menu
(menu items)


/res/raw
(arbitrary files)


/res/values
(strings, integers, colors, styles)


/res/xml
(arbitrary xml)


/
src

(source code)


AndroidManifest.xml
(defines app settings, permissions, components)
COMPONENTS AND
INTENTS
Android App Composition
Primary Components


An Android application is a composition of Activities,
Services, and Broadcast Receivers


Activity


Presents a screen for the user to interact with


Service


Performs a task in the background


Broadcast Receiver


Gets notified when something happens
Intents


Describes the desire to:


Start a new Activity


Start a new Service


Broadcast a message to Broadcast Receivers


Can be sent between applications


Each application specifies intent filters in its manifest


Resolved at runtime by the operating system
Intent Attributes


Component Name


Fully qualified class name of target component


Action


String naming the action to be performed (or that was performed)


Use system-defined actions, or create your own


Action Examples: ACTION_MAIN, ACTION_EDIT, ACTION_CALL


Broadcast Receiver Examples: ACTION_SCREEN_ON,
ACTION_BATTERY_LOW


Data


URI of data to act upon


Category


String containing additional information about the kind of component
that should handle the intent


Extras


Key-Value pairs of additional information
Intent Filtering


OS resolves intents using:


Action


Data


Category


Filters specified in manifest:
<intent-filter >
<action
android:name
=
"
com.myapp.MY_ACTION
"
/>
</intent-filter>
ACTIVITIES
Where the action happens
Activity


Subclass of
android.app.Activity



Generally responsible for a single screen


Acts as “controller” in MVC pattern


Loads one content view (layout)
Activity Lifecycle
public class
MyActivity

extends
Activity {


@Override


protected void
onCreate
(
Bundle
savedInstanceState
) {


// load content view here 


}



@Override


protected void
onStart
() {

}



@Override


protected void
onRestart
() {

}



@Override


protected void
onResume
() {

}



@Override


protected void
onPause
() {

}



@Override


protected void
onStop
() {

}



@Override


protected void
onDestroy
() {

}

}

SERVICES AND
BROADCAST RECEIVERS
Getting things done
Service


Subclass of
android.app.Service



Runs in “background”:


No user interface


Runs in main thread of host application


Need to make your own thread for long tasks


Two primary modes of operation:


Started (
startService
()
) – no communication, can end whenever it
wants


Bound (
bindAction
()
) – allows communication, ends when all
components are unbound
Broadcast Receiver


Subclass of
android.content.BroadcastReceiver



Passive notification


The operating system will call ALL receivers


Two modes of operation:


Normal (sent with
sendBroadcast
()
) - each receiver notified
asynchronously


Ordered (sent with
sendOrderedBroadcast
()
) - each receiver
notified in order
THE MANIFEST FILE
AndroidManifest.xml



Names the Java package of the application


Provides version number and name


Declares minimum and target SDK versions


Describes the components in the application


Associates intents with each component


Declares application permissions


Lists libraries the application links against
Example
AndroidManifest.xml

<
manifest
xmlns:android
=
"http://
schemas.android.com
/
apk
/res/android"

package=
"
com.example.android.notepad
"
>



<uses-
sdk

android:minSdkVersion
=
"11"
/>



<application
android:icon
=
"@
drawable
/
app_notes
"


android:label
=
"@string/
app_name
"
>



<activity
android:name
=
"
NotesList
"


android:label
=
"@string/
title_notes_list
"
>


<intent-filter>


<action
android:name
=
"
android.intent.action.MAIN
"
/>


<category
android:name
=
"
android.intent.category.LAUNCHER
"
/>


</intent-filter>


<intent-filter>


<action
android:name
=
"
android.intent.action.VIEW
"
/>


<action
android:name
=
"
android.intent.action.EDIT
"
/>


<action
android:name
=
"
android.intent.action.PICK
"
/>


<category
android:name
=
"
android.intent.category.DEFAULT
"
/>


<data
android:mimeType
=
"
vnd.android.cursor.dir
/
vnd.google.note

/
>


</intent-filter>


</activity>



</application>


</manifest>