Download ANDROID APPLICATION DEVELOPMENT

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
ANDROID APPLICATION
DEVELOPMENT
Marcin Luckner
Application
APP'S INSIDE
1. The Manifest File
- declare components and required device
features for your application
2. Resources
- separate from the application code
and allow your application to optimize
its behavior for a variety of device
configurations
3. Core framework components
APP COMPONENTS
1. Activities
– an activity represents a singe screen with a user
interface
2. Services
– run in background
– don't provide a user interface
3. Content providers
– manage access to a structured set of data
4. Broadcast receivers
–
receive intents sent
APPLICATION OVERVIEW
• SDK generates an archive file
– Android application package (*.apk)
• APK file contains compiled source code and
resources
• Each application runs in sandboxed
environment
SECURITY SANDBOX
•
•
•
•
Android is a multi-user Linux system
Each app has unique Linux user ID
Starting an app = starting an virtual machine
Each app runs in its own Linux process
APK structure
• AndroidManifest.xml
• META-INF
– CERT.RSA
– CERT.SF
– MANIFEST.MF
• classes.dex
• res
– drawable
– layout
• resources.arcs
The manifest file
The manifest file
1. Names the Java package for the application
2. Describes the components of the app.
Names the classes that implement
each of the components
3. Sets permissions
<manifest>
<uses-permission />
<permission />
<permission-tree />
<permission-group />
<instrumentation />
<uses-sdk />
<uses-configuration />
<uses-feature />
<supports-screens />
<compatible-screens />
<supports-gl-texture />
<application> </application>
<uses-sdk>
<manifest xmlns:android=http://schemas.android.com/apk/res/android >
<uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" />
</manifest>
• Namespace
• The minimum API Level
• The target API Level
<application>
<activity>
<intent-filter>
<action />
<category />
<data />
</intent-filter>
<meta-data />
</activity>
<activity-alias>
<intent-filter> . . . </intent-filter>
<meta-data />
</activity-alias>
<service>
<intent-filter> . . . </intent-filter>
<meta-data/>
</service>
<receiver>
<intent-filter> . . . </intent-filter>
<meta-data />
</receiver>
<provider>
<grant-uri-permission />
<meta-data />
<path-permission />
</provider>
<uses-library />
App’s launcher activity
<activity android:name=".MainActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
• MAIN – the activity does not need initial data
• LAUNCHER – the first activity in the application
Manifest.MF
Signature-Version: 1.0
Created-By: 1.0 (Android)
SHA1-Digest-Manifest: wxqnEAI0UA5nO5QJ8CGMwjkGGWE= ...
Name: res/layout/exchange_component_back_bottom.xml
SHA1-Digest: eACjMjESj7Zkf0cBFTZ0nqWrt7w= ...
Name: res/drawable-hdpi/icon.png SHA1-Digest:
DGEqylP8W0n0iV/ZzBx3MW0WGCA=
Resources
Application resources
1.
Layout Resource
–
–
2.
Drawable
–
–
3.
Define various graphics with bitmaps or XML
Saved in res/drawable and accessed from the R.drawable class
String Resources
–
–
4.
Define the layout for the application UI
Saved in res/layout and accessed from the R.layout class
Define strings, strings arrays, and quantity strings
Saved in res/values and accessed from the R.string,
R.array, R.plurals classes
More resources types
–
–
Define more types of resources, including: Bool, Color, Dimension.
Saved in res/values and accessed from the R.bool,
R.color, R.dimen classes
ACCESSING RESOURCES FROM XML
• Syntax
– @[<package_name>:]<resource_type>/<resource_name>
• Example
– String definition in XML file res/values/strings.xml:
• <resources> <string name="hello">Hello!</string>
</resources>
– XML file retrieves a string value
• <EditText
xmlns:android="http://schemas.android.com/apk/res/androi
d" android:text="@string/hello" />
ACCESSING RESOURCES IN CODE
• Syntax
– [<package_name>.]R.<resource_type>.<resource_name>
• Example
• String definition in XML file res/values/strings.xml:
– <resources> <string name="hello">Hello!</string> </resources>
• Application code retrieves a string
– String string = getString(R.string.hello)
PROVIDING RESOURCES
1. Different types of resources belong
in different sub-directories of res/
2. Alternative resources provide
configuration-specific resource files
3. Always include default
resources so your app does not
depends on specific device configurations
GROUPING RESOURCES TYPES
• Each type of resources should be placed in a specific
subdirectory of the res/ directory
• Resources files cannot be save directly inside the res/
directory
– Compilation error
• The simple resource hierarchy
– res/
• drawable/
– icon.png
• layout/
– main.xml
– info.xml
• values/
– strings.xml
ALTERNATIVE RESOURCES
• Almost every application should provide
alternative resources
to support specific device configurations.
• At runtime, Android detects the current device
configuration and loads the appropriate
resources for your application.
– Create a new directory in res/
named in the form:
<resources_name>-<config_qualifier>
– Save the respective alternative resources
in this new directory
QUALIFIERS
• MCC/MNC (mobile country code/ mobile network)
– mcc260 (Poland), mcc260-mnc003 (Poland-Orange)
• Language and region
– en, fr, en-rUS, fr-rFR, fr-rCA
• Layout direction
– ldrtl (layout-direction-right-to-left), ldltr (vice versa)
• Screen orientation
– port (vertical), land (horizontal)
• UI mode
– car, desk, television, appliance (docks)
RULES
1. You can specify multiple qualifiers for a single
set of resources, separated by dashes.
– drawable-en-rUS-land
– US-English devices in landscape orientation
2. The qualifiers must be in the order
(see above or check the full list)
3. Alternative resources dirs can't be nested
4. Only one value for each qualifier type is
supported
Links
•
•
•
•
•
•
•
Android Security Overview
The AndroidManifest.xml File
Accessing Resources
String Resources
Providing Alternative Resources
Configuration qualifier names
http://slide.es/kamilgrondys
Related documents