Application Fundamentals

URL: http://developer.android.com/guide/topics/fundamentals.html

However, there are ways for an application to share data with other applications and for an application to access system services:

  • It's possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).
  • An application can request permission to access device data such as the user's contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All application permissions must be granted by the user at install time.

four types of application components

Activities
An activity represents a single screen with a user interface. For example, an email application might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Alt hough the activities work together to form a cohesive user experience in the email application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.

An activity is implemented as a subclass ofActivityand you can learn more about it in theActivitiesdeveloper guide.

Services

Aserviceis a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different application, or it might fetch data over the network without blocking user interaction with an activity. Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it.

A service is implemented as a subclass ofServiceand you can learn more about it in theServicesdeveloper guide.

Content providers
A content providermanages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other application s can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information. As such, any application with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person.

Content providers are also useful for reading and writing data that is private to your application and not shared. For example, theNote Padsample application uses a content provider to save notes.

A content provider is implemented as a subclass ofContentProviderand must implement a standard set of APIs that enable other applications to perform transactions. For more information, see theContent Providersdeveloper guide.

Broadcast receivers
A broadcast receiveris a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. 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. Although broadcast receivers don't display a user interface, they may create a status bar notificationto alert the user when a broadcast event occurs. More commonly, though, a broadcas t receiver is just a "gateway" to other components and is intended to do a very minimal amount of work. For instance, it might initiate a service to perform some work based on the event.

A broadcast receiver is implemented as a subclass ofBroadcastReceiverand each broadcast is delivered as anIntentobject. For more information, see theBroadcastReceiverclass.

A unique aspect of the Android system design is that any application can start another application’s component.

When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component.

Therefore, unlike applications on most other systems, Android applications don't have a single entry point (there's nomain()function, for example).

to activate a component in another application, you must deliver a message to the system that specifies yourintentto start a particular component. The system then activates the component for you.

activities(startActivity or startActivityForResult), services(startService, bindService), and broadcast receivers—are activated by an asynchronous message called anintent.

initiate a broadcast: sendBroadcast, sendOrderedBroadcast or sendStickyBroadcast

perform a query to a content provider by calling query on a contentResolver

The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from aContentResolver.

Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. However, broadcast receivers can be either declared in the manifest or created dynamically in code (asBroadcastReceiverobjects) and registered with the system by callingregisterReceiver().

The way the system identifies the components that can respond to an intent is by comparing the intent received to theintent filtersprovided in the manifest file of other applications on the device.

Most of the requirement declarations are informational only and the system doesn't read them, but external services such as Android market do read them in order to provide filtering for users when they search for applications from their device.

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android(安卓)Studio中src/main/res/valu
  2. 2018/8/13
  3. Android(安卓)日历提供器(二)
  4. android APP 获得system权限
  5. android 权限定义的文件,位置
  6. Android,View设置margin
  7. Android(安卓)定时任务
  8. ubuntu 10.04 Android(安卓)编译环境搭建
  9. composer、接口与抽象类学习小结
  10. Android的数据存储