分享一下,今天在Android开发文档-开发者指南中看到的:
App components are the essential building blocks of an Android app. Each component is a different point through which the system can enter your app. Not all components are actual entry points for the user and some depend on each other, but each one exists as its own entity and plays a specific role—each one is a unique building block that helps define your app's overall behavior.
应用程序组件是一个Android应用程序的基本构造块。每个组件都是一个不同的角度,通过该系统,可以进入你的应用程序。不是所有的组件都是为用户和一些互相依赖的实际的切入点,但每一个都作为一个独立的的实体,扮演着特定的角色——每一个都是一个可以帮助确定您的应用程序的整体行为独特的构建快。
There are four different types of app components. Each type serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.
有四种不同类型的应用程序组件。每种类型提供不同的目的,并具有明显的定义组件如何被创建和销毁的生命周期。
Here are the four types of app components:
以下是四种类型的应用程序组件:
Activity:
An activity represents a single screen with a user interface. For example, an email app might have one activity that shows a list of new emails, another activity to compose an email, and another activity for reading emails. Although the activities work together to form a cohesive user experience in the email app, each one is independent of the others. As such, a different app can start any one of these activities (if the email app allows it). For example, a camera app can start the activity in the email app that composes new mail, in order for the user to share a picture.
一个Activity表示为单个屏幕的用户界面。比如,一个email应用程序可能用一个Activity显示新的email列表,用另一个Activity去写Activity,并且使用另外的Activity来阅读Email。虽然活动一起形成一个有凝聚力的用户体验的电子邮件应用程序,但是每一个都是相互独立的。同样的,不同的应用程序可以启动这些Activity中的任何一个(如果Email程序允许他这么做)。比如所,一个相机应用为了分享一张照片可以启动一个Email应用中的Activity来创建一个新的Email。
An activity is implemented as a subclass of Activity and you can learn more about it in the Activitiesdeveloper guide.
你的应用中的Activity应该是继承了Activity的一个子类,如果想要了解更多,可以参照Activities开发指南。
Service:
A service is 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 app, 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.
一个Service是一个运行在后台的、执行耗时操作或者执行跨进程操作的组件。服务没有用户界面。比如所,当用户在其他应用程序的时候,一个服务可能在后台播放音乐或者它可能从网络上读取数据但并不会阻塞用户和Activity交互。另外一个组件,比如一个Activity,为了与Service交互,能够启动服务并且让它运行或者绑定到它。
A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.
你的应用中的Service应该是继承了Service的一个子类,如果你想了解更多,可以参照Services开发指南。
Content Provider:
A content provider manages a shared set of app data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your app can access. Through the content provider, other apps 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 app 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 provider管理一个分享数据的集合。你能够存储数据到文件系统、SQLite数据库、在网络上或者任何其它的你能够访问的持久化存储位置。通过Content Provider,其他应用程序能够查询或者修改数据(如果Content Provider允许它这么做)。比如说,Android系统提供了一个管理用户联系人信息的Content Provider。同样的,任何具有适当权限的应用程序能够查询Content Provider(比如ContactsContract.Data) 去读取或者修改关于特定联系人的信息。
Content providers are also useful for reading and writing data that is private to your app and not shared. For example, the Note Pad sample app uses a content provider to save notes.
Content Provider也能够在读取或者写入你的应用的没有共享的私有数据。比如Note Pad 例子应用程序使用Content Provider来保存日记。
A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other apps to perform transactions. For more information, see the Content Providersdeveloper guide.
你的应用中的ContentProvider应该是ContentProvider的一个子类,并且为了让其他应用程序能够操作事务,必须实现一个标准的API集合。如果您想要得到更多的信息,可以参照Content Providers开发者指南。
Broadcast Receiver:
A broadcast receiver is 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. Apps can also initiate broadcasts—for example, to let other apps 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 notification to alert the user when a broadcast event occurs. More commonly, though, a broadcast 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.
broadcast receiver是一个响应系统范围内发布的广播的组件。很多广播是从系统发布出来的——比如,一个广播通知屏幕已经关闭,电池电量低或者相机已经捕获了一张图片。应用程序也能够发出广播——比如,让其他应用程序知道某些数据已经被下载到设备上,可供它们使用。通过broadcast receiver不能够显示一个用户界面,当广播发生的时候,可以通过创建一个状态栏通知提示用户。更常见的是,一个broadcast receiver仅仅是一个为了做一个非常短暂的事情的到其他组件的“网关”。例如,它可能会启动一个服务来执行基于事件的一些工作。
A broadcast receiver is implemented as a subclass of BroadcastReceiver and each broadcast is delivered as an Intent object. For more information, see the BroadcastReceiver class.
你的应用程序中的一个broadcast receiver是一个继承自BroadcastReceiver的一个子类并且每一个broadcast传第一个Intent 对象。如果您想要获得更多数据,请参考BroadcastReceiver类。
A unique aspect of the Android system design is that any app can start another app’s component. For example, if you want the user to capture a photo with the device camera, there's probably another app that does that and your app can use it, instead of developing an activity to capture a photo yourself. You don't need to incorporate or even link to the code from the camera app. Instead, you can simply start the activity in the camera app that captures a photo. When complete, the photo is even returned to your app so you can use it. To the user, it seems as if the camera is actually a part of your app.
Android系统设计的一个特殊的层面是任何应用都能够启动其他应用的组件。例如,如果你想用户使用设备的相机去捕获一张图片,有可能您通过其他应用的去这么做,而不是自己开发一个Activity去这么做。你不需要把相机应用的代码放到你的应用中去,而是改为简单的启动相机应用的Activity去获得一张图片。当捕捉完成的时候,这张图片将返回到你的应用中,所以你能够使用它。对于用户来讲,相机就好像是你的应用程序的一部分。
When the system starts a component, it starts the process for that app (if it's not already running) and instantiates the classes needed for the component. For example, if your app starts the activity in the camera app that captures a photo, that activity runs in the process that belongs to the camera app, not in your app's process. Therefore, unlike apps on most other systems, Android apps don't have a single entry point (there's no main() function, for example).
当系统启动一个组建的时候,它开始一个这个应用的进程(如果他没有正在运行),并且实例化这个组件所需要的类。例如说,如果你的应用启动一个Camera应用的Activity去不活一张图片,该Activity属于相机应用的进程中,而不是在你的用用的进程中。因此,不像其他大多数系统的应用程序,Android应用程序没有一个单独的入口点(例如,没有main()函数)
Because the system runs each app in a separate process with file permissions that restrict access to other apps, your app cannot directly activate a component from another app. The Android system, however, can. So, to activate a component in another app, you must deliver a message to the system that specifies your intent to start a particular component. The system then activates the component for you.
由于每个应用程序运行在独立于其它应用程序文件权限的系统中,你的呢应用程序不能直接从另一个程序激活一个组件。但是Android系统可以,所以,要激活另一个应用程序的组件,则必须将消息传递到你的Intent所指定的特定组件中,然后系统为你激活那个组件。
相关推荐
在"Android四大组件简述"这个项目中,你可以找到关于这些组件的示例代码和实践应用,通过学习和调试这些示例,可以更深入地理解四大组件的工作原理和使用方式。这将对提升你的Android开发技能大有裨益。
在Android系统中,四大组件是构建应用程序的核心元素,它们分别是Activity、Service、BroadcastReceiver和Content Provider。这四个组件各自承担着不同的职责,共同构成了Android应用的骨架。 **Activity**是用户与...
Activity 是 Android四大组件中最复杂的,需要处理界面逻辑、事件响应、生命周期管理等多个方面。一个 Activity 占据当前的窗口,响应所有窗口事件,具备有控件、菜单等界面元素。 Service Service 服务是 Android...
这个名为“Android 四大组件图解”的PPT文档为初学者提供了一个全面且直观的理解这些组件的机会。 1. **Activity**:Activity是用户与应用交互的界面,如同应用程序的窗口。它可以显示UI,接收用户输入,并处理相关...
在Android应用开发中,四大组件是应用程序的核心组成部分,它们包括Activity、Service、BroadcastReceiver和ContentProvider。本篇文章将重点解析Activity,尤其是其启动模式。Activity是用户与应用程序交互的窗口,...
内容概要:本文详细介绍了Android四大组件(Activity、Service、Broadcast Receiver、Content Provider)的基本概念、生命周期、启动方式及应用场景,并深入讲解了Android中的动画技术,包括帧动画、补间动画和属性...
在Android开发中,四大组件是构建应用程序的核心元素,它们分别是:Activity、Service、BroadcastReceiver以及ContentProvider。这四个组件各自承担着不同的职责,构成了Android应用的骨架。 **Activity** 是用户与...
在Android开发中,四大组件是构建应用...以上就是关于Android四大组件中的ContentProvider和SharedPreferences的基本使用,以及如何插入短信的相关知识。理解并熟练掌握这些内容,对于进行Android应用开发至关重要。
Android 四大组件是构建Android应用程序的核心部分,包括Activity、Service、BroadcastReceiver和ContentProvider。这些组件各自承担着不同的职责...理解并熟练掌握这四大组件,是成为一名合格的Android开发者的关键。
理解并熟练掌握这四大组件和Intent的使用,是成为合格Android开发者的必备技能。开发者需要根据应用的需求,合理设计组件间的交互,利用Intent来灵活地触发组件操作,同时,合理选择数据存储方式,确保数据的安全和...
### Android四大组件解析:深入理解Activity #### 一、引言 在Android开发中,四大组件是构建应用程序的基础。它们分别是Activity、Service、BroadcastReceiver和ContentProvider。本篇文章将重点介绍Activity这一...
本文将深入探讨Android应用程序四大组件之一——Activity的入门知识,并通过一个名为"HelloActivityBasic"的示例来阐述其核心概念。 首先,我们需要理解Activity的基本生命周期。Activity的生命周期包括创建...
Intent是信使,负责完成Android四大组件之间的信息传递,同类、不同类的组件无法直接传递对象,一旦需要沟通只能通过Intent(不建议通过静态变量或静态方法传递数据,容易造成数据异常、内存泄露等问题)。...
【Android 四大组件详解】 ...理解和掌握这四大组件的使用,是成为一名合格的Android开发者的必备技能。在实际开发中,根据需求灵活运用这些组件,可以构建出功能丰富、用户体验良好的Android应用程序。
在Android应用开发中,四大组件是Activity、Service、BroadcastReceiver和ContentProvider,它们构成了应用程序的基础架构。本篇文章将重点探讨四大组件之一的Service,特别是它的基本用法。 Service是Android系统...
在Android开发中,四大组件是构建应用程序的核心元素...总的来说,理解并掌握Android四大组件及其生命周期对于开发高效、稳定的应用至关重要。每个组件都有其特定的使用场景,熟练运用它们可以实现更灵活、强大的功能。