Anda di halaman 1dari 48

Activity Service Broadcastreceiver Contentprovider

Apps are made from components Android instantiates and runs them as needed Each component has its own purpose and APIs

Primary class for user interaction Usually implements a single, focused task that the user can do

Runs in the background to perform long-running operations to support interaction with remote processes

Component that listens for and responds to events

The subscriber in publish/subscribe pattern Events represented by the Intent class and then Broadcast

Component that listens for and responds to events

The subscriber in publish/subscribe pattern Events represented by the Intent class and then Broadcast BroadcastReceiver receives and responds to broadcast event

Store & share data across applications


Uses database-style interface Handles interprocess communication

User enters an address App displays a map of area around the address

See: http://developer.android.com/guide/! " " " "developing/building"

1.! 2.! 3.! 4.!

Define resources Implement application classes Package application Install & run application

Resources are non-source code entities Many different resource types, such as Allows apps to be customized for different devices and users
See: http://developer.android.com/guide/! " " " "topics/resources"

Layout, Strings, Images, Menus, & animations

Types: String, String Array, Plurals

Types: String, String Array, Plurals Typically stored in res/values/*.xml Specified in XML, e.g.,
<string name="hello">Hello World!</string>" Can include formatting and styling

Accessed by other resources as:


@string/string_name"

Accessed in Java as:


R.string.string_name"

"

If your default language is Italian, @string/location_string is


Digita lindirizzo

Otherwise,
Enter Location

UI layout specified in XML files


Some tools allow visual layout

XML files typically stored in


res/layout/*.xml

Accessed in Java as:


R.layout. layout_name"

Accessed by other resources as:


@layout/layout_name"

Can specify different Layout files based on your devices orientation, screen size, etc.

At compilation time, resources are used to generate the R.java class Java code uses the R class to access resources

Usually involves at least one Activity Activity initialization code usually in onCreate()

Typical onCreate() workflow


Restore saved state Set content view Initialize UI elements Link UI elements to code actions

System packages application components & resources into a .apk file Developers specify required application information in a file called AndroidManifest.xml

Information includes: Application Name Components Other


Required permissions Application features Minimum API level

From Eclipse run in the emulator or device From command line


Enable USB Debugging on the device
Settings > Applications > Development > USB debugging

% adb install <path_to_apk>"

The Activity Class

Anda mungkin juga menyukai