Professional Android 4 Application Development Notes

来源:互联网 发布:淘宝出名的店铺 编辑:程序博客网 时间:2024/04/25 09:01

Professional Android 4 Application Development

Chapter 1

Introducting the development framework

  • Android applications normally are written using Java, and executed by Dalvik VM.
  • Each Android application runs in a separate process within its own Dalvik instance.
  • SDK
  • NDK

Android Application Architecture

  • Activity Manager and Fragment Manager
    • to control the lifecycle of your Activities and Fragments
  • Views
    • to construct the UI
  • Notification Manager
    • to provide a consistent and nonintrusive mechanism for signaling your uses
  • Content Providers
    • let your applications share data
  • Resource Manager
    • enables non-code resources,such as strings and graphics
  • Intents
    • provide a mechanism for transferring data between applications and their components

Chapter 2

Android Development Tools

  • Android Virtual Device and SDK Managers
    • to create and manage AVDs
    • to download SDK packages
  • Android Emulator
  • DDMS (Dalvik Debug Monitoring Service)
    • to interrogate active processes
    • to view the stack and heap
    • to watch and pause active threads
    • to explore the filesystem
  • ADB (Android Debug Bridge)
    • a client-server application
    • a daemon running on the device
    • a server runs on PC
  • logcat
    • to view and filter the output of the Android logging system
  • AAPT (Android Asset Packaging Tool)

additional tools

  • ADT plug-in
  • SQLite3
  • Traceview and dmtracedump
  • Hprof-conv
  • Dx
    • to convert Java .class bytecode into Android .dex bytecode
  • Hierarchy Viewer
    • to debug and optimize UI
    • to analyze, debug, and optimize the XML layout defi nitions
  • Lint
    • to optimize your layouts
    • to analyze and optimize your application and resources
  • Draw9patch
    • to simplify the creation of NinePatch graphics
  • Monkey and Monkey Runner
    • Monkey runs within the VM, generating pseudo-random user and system events.
    • Monkey Runner provides an API for writing programs to control the VM from outside your application.
    • to test your applications stability from a UI perspective
  • ProGuard
    • to shrink and obfuscate your code
    • to make your code more difficult to reverse engineer

Chapter 3

What makes an Android Application ?

  • Activities
    • The UI of your application is built around one or more extensions of the Activity class.
    • Activities use Fragments and Views to layout and display information, and to respond to user actions.
  • Services
    • Service components run without a UI,updating your data sources and Activities, triggering Notifi cations, and broadcasting Intents.
    • to perform long running tasks, or those that require no user interaction
  • Content Providers
    • to manage application data and interact with SQL databases
    • to share data across application boundaries
  • Intents
    • interapplication message-passing framework
    • explicit, implicit and broadcast Intents
  • Broadcast Receivers
    • Intent listener
    • to listen for Intents that match the criteria you specify
  • Widgets
    • visual application components that are added to the home screen
  • Notifications
    • to alert users to application events without stealing focus or interrupting their current Activity

Introducing the Application Manifest file

A Closer Look at the AndroidManifest.xml

<manifest xmlns:android=”http://schemas.android.com/apk/res/android”    package=“com.paad.myapp“    android:versionCode=“1“    android:versionName=“0.9 Beta“    android:installLocation=“preferExternal“>    [ ... manifest nodes ... ]</manifest>
  • The manifest tag can include nodes that define the application components, security settings, test classes, and requirements that make up your application.

available manifest sub-nodes

  • uses-sdk
    • to define a minimum and maximum SDK version
    • to define the target SDK version
<uses-sdk android:minSdkVersion=”6”        android:targetSdkVersion=”15”/>
  • uses-configuration
    • to specify input mechanisms that are support by your application
    • be useful for games that require particular input controls
    • any combination of reqFiveWayNav, reqHardKeyboard, reqKeyboardType, reqNavigation, reqTouchScreen
    • for example, a device with a finger touchscreen, a trackball, and either a QUERTY or a twelve-key hardware keyboard, as shown here:
<uses-configuration android:reqTouchScreen=”finger”        android:reqNavigation=”trackball”        android:reqHardKeyboard=”true”        android:reqKeyboardType=”qwerty”/>
<uses-configuration android:reqTouchScreen=”finger”        android:reqNavigation=”trackball”        android:reqHardKeyboard=”true”        android:reqKeyboardType=”twelvekey”/>
  • uses-feature
    • to specify which hardware features your application requires
    • this prevents your application from being installed on a device that doesn’t include a required piece of hardware, such as NFC, as follows:
<uses-feature android:name=”android.hardware.nfc” />
  • optional hardware features: audio, bluetooth, camera, location, microphone, nfc, sensors, telephony, touchscreen, usb, wifi

    • supports-screens
  • to specify the screen size
  • On devices with supported screens, your application is laid out normally using the scaling properties associated with the layout files you supply.
  • On unsupported devices the system may apply a “compatibility mode,” such as pixel scaling to display your application.
<supports-screens android:smallScreens=”false”        android:normalScreens=”true”        android:largeScreens=”true”        android:xlargeScreens=”true”        android:requiresSmallestWidthDp=”480”        android:compatibleWidthLimitDp=”600”        android:largestWidthLimitDp=”720”/>
  • supports-gl-texture
  • uses-permission
    • to declare the user permissions your application requires
<uses-permission    android:name=”android.permission.ACCESS_FINE_LOCATION”/>
  • permission

    • to create permissions to restrict access to shared application components
  • instrumentation

    • to provide a test framework for your application components at run time
    • to monitor your application and its interaction with the system resources
  • application

    • to specify the metadata for your application
    • A manifest can contain only one application node
    • The application node also acts as a container for the Activity, Service, Content Provider, and Broadcast Receiver nodes that specify the application components
    <application android:icon=”@drawable/icon”        android:logo=”@drawable/logo”        android:theme=”@android:style/Theme.Light”        android:name=”.MyApplicationClass”        android:debuggable=”true”>        [ ... application nodes ... ]    </application>

application sub-nodes

  • activity
    • An activity tag is required for every Activity within your application. Trying to start an Activity that’s not defi ned in the manifest will throw a runtime exception.
    • Each Activity node supports intent-filter child tags that define the Intents that can be used to start the Activity
<activity android:name=”.MyActivity” android:label=”@string/app_name”>        <intent-filter>            <action android:name=”android.intent.action.MAIN” />            <category android:name="android.intent.category.LAUNCHER" />        </intent-filter></activity>
  • service
    • a service tag for each Service class used in your application.
    • Service tags also support intent-filter child tags to allow late runtime binding.
<service android:name=”.MyService”></service>
  • provider
    • Provider tags specify each of your application’s Content Providers.
    • Content Providers are used to manage database access and sharing.
<provider android:name=”.MyContentProviderandroid:authorities=”com.paad.myapp.MyContentProvider”/>
  • receiver
    • Each receiver node supports intent-filter child tags that define the Intents that can be used to trigger the receiver
<receiver android:name=”.MyIntentReceiver”>    <intent-filter>        <action android:name=”com.paad.mybroadcastaction” />    </intent-filter></receiver>
  • uses-library
    • to specify a shared library that this application requires
    • You can specify that a particular package is required — which prevents the application from being installed on devices without the specifi ed library — or optional, in which case your application must use refl ection to check for the library before attempting to make use of it
<uses-library android:name=”com.google.android.mapsandroid:required=”false”/>
0 0
原创粉丝点击