当前位置: 代码迷 >> Android >> Android 学习札记(一)
  详细解决方案

Android 学习札记(一)

热度:81   发布时间:2016-05-01 15:49:43.0
Android 学习笔记(一)
Android的四个组件:
1.Activity.
    每一个Activity都会有一个窗口,默认情况下,这个窗口是充满整个屏幕的,也可以将窗口变得比手机屏幕小,或是悬浮在其他的窗口上面。
Each activity is given a default window to draw in. Typically, the window fills the screen, but it might be smaller than the screen and float on top of other windows. An activity can also make use of additional windows — for example, a pop-up dialog that calls for a user response in the midst of the activity, or a window that presents users with vital information when they select a particular item on-screen.

2.Service组件.
    服务没有可视化接口,但可以在后台运行。例如音乐播放、接听电话等等。每一个服务都是android.app.Service的子类。其他程序可以和服务进行通信,当与服务连接成功后,就可以利用服务中共享出来的接口与服务进行通信了。
It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running). While connected, you can communicate with the service through an interface that the service exposes. For the music service, this interface might allow users to pause, rewind, stop, and restart the playback.

Like activities and the other components, services run in the main thread of the application process. So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback). See Processes and Threads, later.

3.Broadcast Receiver广播接收组件.
    接收广播消息,以及对广播消息作出响应。有系统发的广播如时区变化,电池电量不足,收到短信等;也有应用程序自己发的广播,例如通知其他程序数据已经下载完毕,可以使用这些数据了。
    一个应用可以有多个广播接收者, 都继承android.content.BroadcastReceiver这个类。广播接收者和服务一样都没有用户接口,但在广播接收者可以启动一个Activity来响应广播消息。例如,通过显示一个Activity对用户进行提醒,当然也可以采用其他方式。
A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in system code — for example, announcements that the timezone has changed, that the battery is low, that a picture has been taken, or that the user changed a language preference. Applications can also initiate broadcasts — for example, to let other applications know that some data has been downloaded to the device and is available for them to use.
An application can have any number of broadcast receivers to respond to any announcements it considers important. All receivers extend the BroadcastReceiver base class.

Broadcast receivers do not display a user interface. However, they may start an activity in response to the information they receive, or they may use the NotificationManager to alert the user. Notifications can get the user's attention in various ways — flashing the backlight, vibrating the device, playing a sound, and so on. They typically place a persistent icon in the status bar, which users can open to get the message。

4.ContentProviders组件.
    内容提供者可以为其他应用程序提供数据。这些数据可以保存在文件系统中,例如SQLite或其他任何格式的文件。每一个内容提供者都是一个类,这些类都需要从android.content.ContentProvider.类继承。
    在ContentProvider类中定义了一系列的方法,通过这些方法可以使其他的应用程序获得和存储内容提供者所支持的数据。但是在应用程序中不能直接调用这些方法,而需要通过android.content.ContentResolver类的方法来调用内容提供者中提供的方法。
A content provider makes a specific set of the application's data available to other applications. The data can be stored in the file system, in an SQLite database, or in any other manner that makes sense. The content provider extends the ContentProvider base class to implement a standard set of methods that enable other applications to retrieve and store data of the type it controls. However, applications do not call these methods directly. Rather they use a ContentResolver object and call its methods instead. A ContentResolver can talk to any content provider; it cooperates with the provider to manage any interprocess communication that's involved.
  相关解决方案