Android 架构
Android 应用程序组件
- Activities
一个活动标识一个具有用户界面的单一屏幕public class MainActivity extends Activity { }
- Services
服务是运行在后台,执行长时间操作的组件。举个例子,服务可以是用户在使用不同的程序时在后台播放音乐,或者在活动中通过网络获取数据但不阻塞用户交互。public class MyService extends Service { }
- Broadcast Receivers
广播接收器简单地响应从其他应用程序或者系统发来的广播消息。举个例子,应用程序可以发起广播来让其他应用程序知道一些数据已经被下载到设备,并且可以供他们使用。因此广播接收器会拦截这些通信并采取适当的行动。public class MyReceiver extends BroadcastReceiver { }
- Content Providers
内容提供者组件通过请求从一个应用程序到另一个应用程序提供数据。这些请求由ContentResolver类的方法来处理。这些数据可以是存储在文件系统、数据库或者其他其他地方。
内容提供者是ContentProvider类的子类,并实现一套标准的API,以便其他应用程序来执行事务。public class MyContentProvider extends ContentProvider { }
activity
- 一个界面就是一个 activity
- 生命周期
Unit 3 How to finish your first Android app
- How to handle the EditorAction event
EditorInfo
- How to get and set the text for widgets
- How to handle the Click event
- How to set the launcher icon for an app
Unit 4 How to test and debug app
- the goal of testing is to find errors (bugs) and make an app fail.
- the goal of debugging is to fix all of the bugs that you find during testing
Unit 5 How to work with layouts and widgets
widgets
EditText
- 邮件地址
- 密码
- 可使用的类型
- windowSoftInputMode attribute
check boxes
radio buttons
spinners
seek bars
Image
设置视图是否可见
scroll bars
别人写的完整代码
layouts
LinearLayout
TableLayout
FrameLayout
混合布局(nest layouts)
别人写的总结
Unit 6 How to handle events
组件上的事件
- 组件类型
- high-level
- low-level
listener
- use
- 不继承,创建一个监听器对象【匿名类 anonymous class】
- 匿名内部类【anonymous inner class】
high-level
low-level
- keyEvent class
- touch events
Chapter 7 How to work with themes and styles
themes
-
黑马
-
How to supply different themes for different APIs(theme 应用在整个程序或当前界面)
-
How to convert an existing project to the AppCompat theme
- 添加依赖
- 按照下图所示
styles
- heima(styles 应用在控件上)
- How to define a style
- How to create a style sheet
How to work with themes
- an EditText widget that uses a TextApperance style
- how to apply themes
Chapter 8 How to work with menus and preferences
How to work with menus
- defined
- how to display an options menu
- How to handle option menu events
- How to start a new activity
How to work with preferences
- PreferenceActivity是一个抽象类,继承于ListActivity,以列表形式视图来展现界面,加载的整个View也是基于ListActivity中那个ListView的,其最主要的优势在于添加Preference后可让其状态持久化储存
- How to define preferences
- 样式属性
- How to display preferences
- How to get preferences
- How to use preferences
Chapter 9 How to work with fragments
How to use single-pane layouts for small screens
- demo
- How to display a fragment in an activity
- How to create a preference fragment
- How to display a preference fragment in an activity
How to use multi-pane layouts for large screens
- How to add multiple fragments to a layout
- How to detect screen width
- How to control the soft keyboard
黑马
- 知识点
- 实例
Chapter 10 How to work with threads,files, adapters, and intents
threads
files
- How to download a file from the Internet
- How to parse an XML file
- 黑马
adapters
- How to create the layout for a list view
- How to use an adapter to display data in a list view
- How to handle events for an adapter
intents
- How to pass data between activities
- How to dial or call a phone number
- Intent 作用
- Intent 黑马
- 显式意图
- 隐式意图
Chapter 11 How to work with services and notifications
黑马
- 服务的创建(类似于没有界面的activity,在后台长期运行,不需要有界面)
- 服务的生命周期
- 服务的启动方式
startService
bindService
How to work with services
- How to register a service
- How to start and stop a service
- How to test a service
Chapter 12 How to work with broadcast receivers
黑马
-
简介
-
入门
静态注册,系统自动注册好的
动态注册
-
实例
所以这个号码拨打不出去 -
自定义广播
-
例
-
广播类型
book
- How to code a receiver for the connectivity changed broadcast
How to work with custom broadcasts