android application developmentlucknerm/userfiles/downloads/android/...app's inside 1. the...
TRANSCRIPT
![Page 1: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/1.jpg)
ANDROID APPLICATION DEVELOPMENT
Marcin Luckner
![Page 2: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/2.jpg)
Application
![Page 3: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/3.jpg)
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
![Page 4: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/4.jpg)
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
![Page 5: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/5.jpg)
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
![Page 6: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/6.jpg)
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
![Page 7: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/7.jpg)
APK structure
• AndroidManifest.xml • META-INF
– CERT.RSA – CERT.SF – MANIFEST.MF
• classes.dex • res
– drawable – layout
• resources.arcs
![Page 8: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/8.jpg)
The manifest file
![Page 9: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/9.jpg)
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
![Page 10: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/10.jpg)
<manifest>
<uses-permission /> <permission /> <permission-tree /> <permission-group /> <instrumentation /> <uses-sdk /> <uses-configuration /> <uses-feature /> <supports-screens /> <compatible-screens /> <supports-gl-texture />
<application> </application>
![Page 11: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/11.jpg)
<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
![Page 12: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/12.jpg)
<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 />
![Page 13: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/13.jpg)
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
![Page 14: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/14.jpg)
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=
![Page 15: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/15.jpg)
Resources
![Page 16: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/16.jpg)
Application resources
1. Layout Resource – Define the layout for the application UI – Saved in res/layout and accessed from the R.layout class
2. Drawable – Define various graphics with bitmaps or XML – Saved in res/drawable and accessed from the R.drawable class
3. String Resources – Define strings, strings arrays, and quantity strings – Saved in res/values and accessed from the R.string,
R.array, R.plurals classes
4. 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
![Page 17: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/17.jpg)
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/android" android:text="@string/hello" />
![Page 18: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/18.jpg)
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)
![Page 19: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/19.jpg)
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
![Page 20: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/20.jpg)
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
![Page 21: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/21.jpg)
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
![Page 22: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/22.jpg)
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)
![Page 23: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/23.jpg)
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
![Page 24: ANDROID APPLICATION DEVELOPMENTlucknerm/userfiles/downloads/Android/...APP'S INSIDE 1. The Manifest File - declare components and required device features for your application 2. Resources](https://reader034.vdocuments.net/reader034/viewer/2022043019/5f3b8502dd529d12c37b0e14/html5/thumbnails/24.jpg)
Links
• Android Security Overview
• The AndroidManifest.xml File
• Accessing Resources
• String Resources
• Providing Alternative Resources
• Configuration qualifier names
• http://slide.es/kamilgrondys