前言..................................................................................xvii
第1章 Android概述............................................................1
概述..............................................................................................................................1
完整性.................................................................................................................1
开源平台.............................................................................................................2
为移动设备而设计.............................................................................................2
历史..............................................................................................................................3
Google的动机......................................................................................................3
开放手持设备联盟.............................................................................................3
Android的版本............................................................................................................4
总结..............................................................................................................................5
第2章 Android的架构......................................................... 7
架构概述......................................................................................................................7
Linux系统....................................................................................................................7
可移植性.............................................................................................................7
安全性.................................................................................................................8
丰富的特性.........................................................................................................8
本地库..........................................................................................................................9
Dalvik 虚拟机..............................................................................................................9
Android与Java...................................................................................................10
应用程序框架............................................................................................................11
应用程序....................................................................................................................12
APK文件...........................................................................................................12
应用程序签名...................................................................................................12
应用程序发布...................................................................................................12
总结............................................................................................................................13
第3章 快速入门...............................................................15
安装Android SDK.....................................................................................................15
设置PATH环境变量..........................................................................................16
安装 Eclipse.......................................................................................................16
Eclipse的工作区................................................................................................17
安装Android 开发工具.....................................................................................17
Hello, World程序.......................................................................................................18
创建新项目.......................................................................................................18
Manifest文件.....................................................................................................20
Layout(布局)XML代码...............................................................................21
Strings(字符串)文件....................................................................................21
R(资源)文件.................................................................................................22
Java源码文件....................................................................................................22
仿真器........................................................................................................................23
仿真器和真机...................................................................................................25
总结............................................................................................................................26
第4章 基本构件...............................................................27
什么是基本构件........................................................................................................27
一个实际的例子........................................................................................................27
活动(Activity)......................................................................................................28
活动的生命周期...............................................................................................28
Intent..........................................................................................................................30
服务(Service)........................................................................................................31
内容提供器(Content Provider)............................................................................32
广播接收器(Broadcast Receiver)........................................................................34
应用程序上下文(Application Context)...............................................................34
总结............................................................................................................................35
第5章 Yamba项目简介 ....................................................37
Yamba 应用程序.......................................................................................................37
设计原则....................................................................................................................39
项目设计....................................................................................................................40
第1部分:Android用户界面....................................................................................41
构建一个活动...................................................................................................41
网络和多线程...................................................................................................41
调试Android 程序.............................................................................................41
第2部分:首选项、文件系统、选项菜单及Intent................................................41
活动...................................................................................................................42
菜单系统与Intent..............................................................................................42
文件系统...........................................................................................................42
第3部分:Android服务............................................................................................42
服务...................................................................................................................42
应用程序对象...................................................................................................42
第4部分:使用数据库..............................................................................................43
SQLite及Android对它的支持...........................................................................43
再次重构代码...................................................................................................43
第5部分:列表(List)与适配器(Adapter)......................................................43
时间轴(Timeline)活动.................................................................................43
再重构一次.......................................................................................................44
第6部分:广播接收器(Broadcast Receiver)......................................................44
启动接收器与网络连接接收器.......................................................................44
时间轴(Timeline)接收器.............................................................................44
权限...................................................................................................................44
第7部分:内容提供器(Content Provider)..........................................................44
状态数据...........................................................................................................45
Android小部件..................................................................................................45
第8部分:系统服务..................................................................................................45
指南针与位置...................................................................................................45
Intent服务、提醒及通知..................................................................................45
总结............................................................................................................................46
第6章 Android用户界面 ...................................................47
创建用户界面的两种方法........................................................................................47
声明式的用户界面...........................................................................................47
编程式的用户界面...........................................................................................48
各取所长...........................................................................................................48
控件与布局................................................................................................................48
LinearLayout......................................................................................................49
TableLayout.......................................................................................................50
FrameLayout......................................................................................................50
RelativeLayout...................................................................................................50
AbsoluteLayout..................................................................................................50
启动Yamba项目........................................................................................................50
StatusActivity布局.....................................................................................................52
控件的重要属性...............................................................................................54
字符串资源.......................................................................................................56
StatusActivity Java类.................................................................................................56
编写具体应用的对象,以及初始化相关代码...............................................57
保存文件:编译代码和构建项目...................................................................59
添加库jtwitter.jar...............................................................................................60
更新Manifest文件,获取Internet权限.............................................................61
Android的日志机制..................................................................................................62
LogCat................................................................................................................63
Android的线程机制..................................................................................................65
单线程执行.......................................................................................................65
多线程执行.......................................................................................................66
AsyncTask..........................................................................................................67
其他UI事件...............................................................................................................70
添加图片与色彩........................................................................................................75
添加图片...........................................................................................................75
添加色彩...........................................................................................................78
多版本资源文件........................................................................................................80
优化用户界面............................................................................................................81
Hierarchy Viewer 工具......................................................................................82
总结............................................................................................................................83
第7章 首选项、文件系统、选项菜单及Intent .................. 85
首选项........................................................................................................................85
资源文件...........................................................................................................86
PrefsActivity类..................................................................................................89
修改Manifest文件.............................................................................................90
选项菜单....................................................................................................................91
菜单的资源文件...............................................................................................92
Android系统资源..............................................................................................93
更新StatusActivity,加载菜单.........................................................................93
更新StatusActivity,捕获菜单事件.................................................................94
字符串资源.......................................................................................................95
Shared Preferences.....................................................................................................96
文件系统简介............................................................................................................98
浏览文件系统...................................................................................................98
文件系统的分区...............................................................................................99
系统分区.........................................................................................................100
SDCard 分区....................................................................................................100
用户数据分区.................................................................................................100
文件系统的安全机制.....................................................................................101
总结..........................................................................................................................102
第8章 服务.....................................................................103
Yamba的Application对象........................................................................................104
YambaApplication类.......................................................................................104
更新Manifest文件...........................................................................................106
简化 StatusActivity..........................................................................................107
UpdaterService.........................................................................................................108
创建 UpdaterServiceJava类............................................................................108
更新Manifest文件...........................................................................................110
添加菜单项.....................................................................................................111
更新选项菜单的事件处理.............................................................................111
测试服务.........................................................................................................112
在服务中循环..........................................................................................................113
测试服务.........................................................................................................116
从 Twitter 读取数据................................................................................................117
测试服务.........................................................................................................121
总结..........................................................................................................................121
第9章 数据库.................................................................123
关于 SQLite.............................................................................................................123
DbHelper类..............................................................................................................124
数据库模式及其创建.....................................................................................124
4种主要操作...................................................................................................125
游标.................................................................................................................126
第一个例子..............................................................................................................127
修改UpdaterService.................................................................................................129
测试服务.........................................................................................................133
数据库约束.....................................................................................................135
重构数据库访问......................................................................................................136
总结..........................................................................................................................142
第10章 列表与适配器 ....................................................145
TimelineActivity......................................................................................................145
TimelineActivity的基本布局..................................................................................146
ScrollView简介................................................................................................146
创建TimelineActivity类..................................................................................147
关于适配器..............................................................................................................150
为TimelineActivity添加ListView...................................................................151
创建一个单行消息布局.................................................................................152
在TimelineActivity.java中创建适配器...........................................................153
TimelineAdapter......................................................................................................155
ViewBinder: 取代TimelineAdapter的更好选择.....................................................158
更新Manifest文件...................................................................................................160
程序初始设置.................................................................................................162
Base Activity............................................................................................................163
服务开关.........................................................................................................163
总结..........................................................................................................................170
第11章 广播接收器(Broadcast Receiver) ................. 171
关于Broadcast Receiver..........................................................................................171
BootReceiver............................................................................................................172
将BootReceiver注册到AndroidManifest文件................................................173
测试 BootReceiver..........................................................................................173
TimelineReceiver.....................................................................................................173
广播Intent................................................................................................................175
Network Receiver....................................................................................................177
添加用于发送和接收广播的自定义权限..............................................................180
在Manifest文件中声明权限...........................................................................180
为更新服务应用权限机制.............................................................................181
为TimelineReceiver应用权限机制.................................................................183
总结..........................................................................................................................183
第12章 内容提供器(Content Provider)...................... 185
创建Content Provider..............................................................................................185
定义URI...........................................................................................................186
插入数据.........................................................................................................187
更新数据.........................................................................................................188
删除数据.........................................................................................................189
查询数据.........................................................................................................190
获取数据类型.................................................................................................191
更新Android Manifest文件.............................................................................192
在小部件中使用Content Provider..........................................................................192
实现YambaWidget类.......................................................................................193
创建XML布局.................................................................................................196
创建AppWidgetProviderInfo文件...................................................................197
更新Manifest文件...........................................................................................197
测试小部件.....................................................................................................198
总结..........................................................................................................................198
第13章 系统服务...........................................................201
实例:指南针..........................................................................................................201
使用系统服务的一般步骤.............................................................................201
获取指南针的更新.........................................................................................202
指南针的主活动.............................................................................................203
自定义的表盘小部件.....................................................................................206
位置服务..................................................................................................................208
实例: Where Am I............................................................................................208
用上位置服务,重构Yamba..................................................................................213
更新首选项.....................................................................................................213
更新Yamba程序..............................................................................................214
更新Status Activity..........................................................................................215
Intent服务................................................................................................................219
Alarms..............................................................................................................222
在首选项中添加Interval选项.........................................................................223
更新BootReceiver............................................................................................224
发送通知..................................................................................................................226
总结..........................................................................................................................229
第14章 Android接口描述语言 ........................................231
实现远程服务..........................................................................................................231
编写AIDL........................................................................................................232
实现服务.........................................................................................................233
实现一个Parcel................................................................................................235
注册到Manifest文件.......................................................................................236
实现远程客户端......................................................................................................237
绑定到远程服务.............................................................................................238
测试运行.........................................................................................................241
总结..........................................................................................................................242
第15章 Native Development Kit (NDK) .........................243
NDK是什么.............................................................................................................243
NDK的功能.............................................................................................................244
工具链.............................................................................................................244
打包库文件.....................................................................................................244
文档与标准头文件.........................................................................................244
NDK实例:计算菲波那契数列.............................................................................245
FibLib...............................................................................................................246
JNI 头文件.......................................................................................................247
C 实现..............................................................................................................249
Makefile...........................................................................................................251
构建共享库.....................................................................................................251
Fibonacci Activity............................................................................................251
测试所有的工作.............................................................................................253
总结..........................................................................................................................254
索引.................................................................................255