anroid development part.1
DESCRIPTION
在公司内部讲解的一个andoid开发的ppt.TRANSCRIPT
![Page 2: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/2.jpg)
![Page 3: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/3.jpg)
不仅仅是一部手机• 出色的操控性的用户体验• 华丽的界面• 出色的上网体验 safari
• 娱乐 - 游戏,音乐• market
• 非常多的应用程序• 相对成熟的操作系统• 相对成熟的商业体系
代表智能机的一种趋势
![Page 4: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/4.jpg)
华丽的挣扎
• 历史悠久,使用人群基数非常大• 软件也是比较多• 在现在手机系统更新速度越来越快的今天,界面和操控无疑有点 out
• 即将退出历史舞台
![Page 5: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/5.jpg)
• 优势在于手机上的 Office 协同软件• 更新速度不是一个慢字了得• 期待还在产房里的 Windows Phone 7
温室的花朵
![Page 6: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/6.jpg)
• Google’s 开源的操作系统• 丰富的网络应用功能 Google map, youtube, search
• Google adsense for mobile
• Market 已经快超万• 系统更新速度快,目前 2.1
![Page 7: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/7.jpg)
Scan barcode Goggles
![Page 8: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/8.jpg)
• Architecture
• Application
• Activity
•Interaction
![Page 9: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/9.jpg)
![Page 10: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/10.jpg)
![Page 11: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/11.jpg)
AndroidManifest.xml 是系统的控制文件,它告诉系统如何处理你所创建的所有 顶层组件 ( 尤其是 Activities, 服务 ,Intent 接收器和 ContentProvider) 。
![Page 12: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/12.jpg)
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myAndroidApp"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<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>
<activity android:name="SettingActivity"></activity>
<activity android:name="SensorActivity"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myAndroidApp"
android:versionCode="1"
android:versionName="1.0">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<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>
<activity android:name="SettingActivity"></activity>
<activity android:name="SensorActivity"></activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
Code Snippet
![Page 13: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/13.jpg)
Drawable : png, .9.png, .jpg files 这些类型的文件被编译进下列这些图表资源列表Layouts :可编译成屏幕布局的 XML 文件,编译时, Android 产生一个叫 R 的类,它指向你程序中所有的资源。Values :可编译成多种类型资源的 XML 文件。例如多语言问题的解决(字符串),数字常量。Assets : Raw 格式文件。这里的任何文件都将直接被复制到设备上。编译产品时,这些数据不会被编译,它们被直接加入到程序包里。
![Page 14: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/14.jpg)
• Activity 是最基本的 Andorid 应用程序组件,应用程序中,一个活动通常就是一个单独的屏幕。• 同时只可能有一个页面是活动 Activity
• 每个 Activity 之间可以通过 Intent 通迅• 每个 Activity 都有自己的生命周期
![Page 15: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/15.jpg)
Lifecycle of an Activity
![Page 16: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/16.jpg)
![Page 17: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/17.jpg)
![Page 18: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/18.jpg)
startActivity(new Intent("com.myAndroidApp.action.SETTING"));startActivity(new Intent("com.myAndroidApp.action.SETTING"));
Code Snippet
<activity android:name=".SettingActivity">
<intent-filter>
<action android:name="com.myAndroidApp.action.SETTING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".SettingActivity">
<intent-filter>
<action android:name="com.myAndroidApp.action.SETTING"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
Intent intent = new Intent(Boy.class, Girl.class);startActivity(intent);Intent intent = new Intent(Boy.class, Girl.class);startActivity(intent);
一、
二、
![Page 19: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/19.jpg)
关于 Intent—— 组件之间的联系Intent - 执行某操作的一个抽象描述。
![Page 20: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/20.jpg)
显式 Intent 用于已有意向的情况例如从 Boy 跳转到 Girl 的 Activity
Intent intent = new Intent(Boy.class, Girl.class);startActivity(intent);Intent intent = new Intent(Boy.class, Girl.class);startActivity(intent);
方式一、非诚勿扰
BoyBoy GirlGirlIntentIntent
![Page 21: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/21.jpg)
发布发布
存档存档
年 龄身 高体 重三 围
年 龄身 高体 重三 围
查找关键字查找关键字 合适合适 结婚结婚
方式二、征婚
![Page 22: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/22.jpg)
发布发布
存档存档
Manifest 添加Intent-filterManifest 添加Intent-filter
The Intent-filter workflow
查找关键interfilte
r
查找关键interfilte
r
Intent找到最合适
Intent找到最合适
关联启动关联启动
隐式 Intent
![Page 23: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/23.jpg)
<activity android:name=".SettingActivity"><intent-filter>
<action android:name="com.myAndroidApp.action.SETTING"/><category android:name="android.intent.category.DEFAULT"/>
</intent-filter></activity>
<activity android:name=".SettingActivity"><intent-filter>
<action android:name="com.myAndroidApp.action.SETTING"/><category android:name="android.intent.category.DEFAULT"/>
</intent-filter></activity>
Code Snippet
MainActivity.javaString SETTING_ACTION = "com.myAndroidApp.action.SETTING";Intent intent = new Intent();intent.setAction(SETTING_ACTION );startActivity(intent)
MainActivity.javaString SETTING_ACTION = "com.myAndroidApp.action.SETTING";Intent intent = new Intent();intent.setAction(SETTING_ACTION );startActivity(intent)
![Page 24: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/24.jpg)
Intent-filter 匹配过程
![Page 25: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/25.jpg)
Intent
![Page 26: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/26.jpg)
• 一种以 KEY , VAL 方式存储的数据的类型,类似MAP 。
• 但不能传递复杂的数据类型,只能传递例如:字符串,数字型等类型。
在何时用?Intent 在各组件之间传递数据里就用 Bundle 类型来传递。
注:也可参见广播章里的代码。
![Page 27: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/27.jpg)
视图 (Views) 可以将其自身绘制到屏幕上。Android 的用户界面由一系列的视图树 ( trees of views )构成。接口都是由一组以树的形式出现的视图组成的。开发者可 以通过创建一个新的视图的方法来使用自定义的图形处理技术 ( 比如开发游戏,或者是 使用了不常用的用户图形 (UI)窗口界面 (widget))
Layout 布局
视觉控件
Android UI
![Page 28: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/28.jpg)
大概写了 20 个常用组件
![Page 29: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/29.jpg)
• ContentProvider / ContentResolver / UriMatcher
• Broadcast / BroadcastReceiver / Notification
![Page 30: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/30.jpg)
• Notification – 任务栏通知• Services – 后台服务• Broadcast – 广播• Broadcast Receiver – 广播接收器
注:不是所有的程序都必须有以下组件。
![Page 31: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/31.jpg)
BroadcastBroadcast
Broadcast Receiver(get intent)Broadcast Receiver(get intent)
ServicesServicesActivitiesActivities
IntentIntent
BroadcastBroadcast
IntentIntent
组件 /
进程级的
Ob
server
广播
![Page 32: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/32.jpg)
1. 添加 Intent-filter – manifest.xml
2. 添加广播数据 Bundle实例到 intent
3. 广播到某个组件 sendBroadcast(intent)
4. 组件接收广播 (该组件继承自 BroadcastReceiver)
onReceive(Context context, Intent intent)
5. 通知到任务栏 notification
Bundle —— 理解成 Hash Map ,但只允许存成基本的数据类型对,例如String , int 。
![Page 33: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/33.jpg)
Manifest.xml<receiver android:name="Receiver">
<intent-filter> <!-- 和 Intent 中的 action 对应 --> <action android:name="com.myAndroidApp.action.Receiver"/> </intent-filter>
</receiver>
Manifest.xml<receiver android:name="Receiver">
<intent-filter> <!-- 和 Intent 中的 action 对应 --> <action android:name="com.myAndroidApp.action.Receiver"/> </intent-filter>
</receiver>
Code Snippet
MainActivity.javaIntent intent = new Intent();intent.setAction(RECEIVER_ACTION);Bundle buddle = new Bundle();buddle.putString("title", "Email");buddle.putString("content","ranklau");intent.putExtras(buddle);sendBroadcast(intent);
MainActivity.javaIntent intent = new Intent();intent.setAction(RECEIVER_ACTION);Bundle buddle = new Bundle();buddle.putString("title", "Email");buddle.putString("content","ranklau");intent.putExtras(buddle);sendBroadcast(intent);
Receiver.javapublic class Receiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); String title = bundle.getString("title"); String content = bundle.getString("content"); Notification notification = new Notification(R.drawable.icon1, "New notification", System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); notification.setLatestEventInfo(context, title, content, contentIntent); NotificationManager notificationManager = (NotificationManager) context.getSystemService(android.content.Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); }}
Receiver.javapublic class Receiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) { Bundle bundle = intent.getExtras(); String title = bundle.getString("title"); String content = bundle.getString("content"); Notification notification = new Notification(R.drawable.icon1, "New notification", System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0); notification.setLatestEventInfo(context, title, content, contentIntent); NotificationManager notificationManager = (NotificationManager) context.getSystemService(android.content.Context.NOTIFICATION_SERVICE); notificationManager.notify(NOTIFICATION_ID, notification); }}
![Page 34: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/34.jpg)
Difference of startService and bindService
![Page 35: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/35.jpg)
![Page 36: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/36.jpg)
Query
Delete
Update
Insert
程序间 数据访问 操作?
![Page 37: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/37.jpg)
例如使用内容管理器 (ContentProvider) 来访问联系人列表。你的应用程序也可以使用其它程序通过内容管理器提 供的数据,同时你也可以定义你自己的内容管理器来向其它应用提供数据访问服务。
注意,它是同步执行的。
![Page 38: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/38.jpg)
A :标准前缀,用来说明一个 Content Provider 控制这些数据,无法改变的;B : URI 的标识,它定义了是哪个 Content Provider提供这些数据。对于第三方应用程序,为了保证URI标识的唯一性,它必须是一个完整的、小写的 类名。这个标识在 <provider> 元素的 authorities属性中说明:<provider name=”.TransportationProvider”
authorities=”com.example.transportationprovider” . . . >
C :路径, Content Provider 使用这些路径来确定当前需要生什么类型的数据, URI 中可能不包括路径,也可能包括多个;D :如果URI 中包含,表示需要获取的记录的 ID;如果没有 ID ,就表示返回全部;由于 URI 通常比较长,而且有时候容易出错,切难以理解。所以,在 Android当中定义了一些辅助类,并且定义了一些常量来代替这些长字符串,例如: People.CONTENT_URI
What is the URI?
![Page 39: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/39.jpg)
• 访问一致性,即接口描述已经出现成的了, URI 已经描述。
• 天生具有权限控制(例如 FTP , HTTP , HTTPS 协议等等)
但是, URI传递不能数据类型就比较麻烦,所以。我想Android 通过 bundle 作参数来传递复杂参数
![Page 40: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/40.jpg)
•content://media/internal/images
这个 URI 将返回设备上存储的所有图片•content://contacts/people/
这个 URI 将返回设备上的所有联系人信息•content://contacts/people/45
这个 URI返回单个结果(联系人信息中 ID 为 45 的联系人记录)
•Intent intent= new Intent(Intent.DIAL_ACTION,Uri.parse("tel:5551212"));
•startActivity(this.class,intent) //启动拨号程序。
![Page 41: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/41.jpg)
•ContentProvider + UriMatcher
•ContentResolver ( Activity 方法)
![Page 42: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/42.jpg)
好象是和 COM很相似…
![Page 44: Anroid development part.1](https://reader035.vdocuments.pub/reader035/viewer/2022062703/5552f56eb4c90587048b4d5d/html5/thumbnails/44.jpg)