Professional Android 4 Application Development Notes
2015-06-21 11:56
615 查看
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 Managerto 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 Managersto 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-inSQLite3
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 ?
ActivitiesThe 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-sdkto 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
activityAn 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=”.MyContentProvider” android: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.maps” android:required=”false”/>
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories