安卓应用基础外文翻译资料

 2022-07-20 02:07

Application Fundamentals

Along with any data and resource files required by the application — is bundled by the

to their devices. All the code in a single .apk file is considered to be one applications (provided those applications permit it). For example, if your than develop your own. Your application doesn#39;t incorporate the code of the other

message to the chosen contact, and other activities to review old messages or change settings. Though they work together to form a cohesive user interface, each activity is independent of the others. Each one is implemented as a subclass of the Activity base class. An application might consist of just one activity or, like the text messaging application just mentioned, it may contain several. What the activities are, and how many there are depends, of course, on the application and its design. Typically, one of the activities is marked as the first one that should be presented to the user when the application is launched. Moving from one activity to another is accomplished by having the current activity start the next one.

Services A service doesn#39;t have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something and provide the result to activities that need it. Each service extends the Service base class.

Broadcast receivers 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 time zone 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#39;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 Content providers A content provider makes a specific set of the application#39;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#39;s involved. See the separate Content Providers document for more information on using content providers. Whenever there#39;s a request that should be handled by a particular component, Android makes sure that the application process of the component is running, starting it if necessary, and that an appropriate instance of the component is available, creating the instance if necessary.

Activating Components

Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent. Intents bind individual components to each other at runtime (you can think of them as the messengers that request an action from other components), whether the component belongs to your application or another.

An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component—an intent can be either explicit or implicit, respectively.

For activities and services, an intent defines the action to perform (for example, to 'view' or 'send' something) and may specify the URI of the data to act on (among other things that the component being started might need to know). For example, an intent might convey a request for an activity to show an image or to open a web page. In some cases, you can start an activity to receive a result, in which case, the activity also returns the result in an Intent (for example, you can issue an intent to let the user pick a personal contact and have it returned to you—the return intent includes a URI pointing to the chosen contact).

For broadcast receivers, the intent simply defines the announcement being broadcast (for example, a broadcast to indicate the device battery is low includes only a known action string that indicates 'battery is low').

The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver. The content resolver handles all direct transactions with the content provider so that the component that#39;s performing transactions with the provider doesn#39;t need to and instead calls methods on the ContentResolver object. This leaves a layer of abstraction between the content provider and the component requesting information (for security). There are separate methods for activating each type of component: You can start an activity (or give it something new to do) by passing an Intent to startActivity() or startActivityForResult() (when you want the activity to return a result). You can start a service (or give new instructions to an ongoing service) by passing an Intent to startService(). Or you can bind to the service by passing

全文共16555字,剩余内容已隐藏,支付完成后下载完整资料


安卓应用基础

应用程序是通过java语言开发的,通过绑定一些应用所需要的东西,例如:编

Java代码,加上数据和一些资源文件,使用一个apt的工具将所有的东西封装成一

android包,这个文件的文件后缀是.apk。这个文件是分发并安装应用程序到移动设备。Android有四大应用程序组件 Android的一个很重要的中心特征就是一个应用程序能充分利用其他的应用程序的一些组件(前提是被允许的) 例如:如果的当前开发的应用需要一个滚动的列表去展示相片并且当时其他的程序已经开发了一个合适的滚动列表并且对其他人可用,你可以调用这个滚动的列表来完成你的工作而不是开发你自己的。你的应用不需要包含那个应用的代码或来链接它。 相反,它只是简单的在你需要它是启动这部分的应用 为了实现这部分的功能,当前系统必须能启动其他应用程序进程的功能当那些部分它需要时,并且为这部分的java对象初始化这个java对象。因此,不想在其他系统中的应用程序,android应用程序不需要一个单一的入口点(例如:没有main())而是,提供了实例化和运行所需的必备组件。

Android有四大应用程序组件

1:Activity 一个Activity基类是为展示可视化用户接口。例如:一个Activity可以显示一个供用户选择的菜单列表,或者可以展示一些图片以及对应的说明。一个短信的应用有一个活动显示发送消息的一系列的联系人,第二个活动去编写信息文本去选择联系人,第三个活动去查看以前的信息或修改一些设置。虽然它们组成了一个内聚的用户界面,每一个活动都和其他的的相互独立,每一个都继承Activity,是Activity的子类。一个应用程序可以只有一个Activity,但是也可以有多个,比如刚刚提到的文本应用。每个程序的作用,有多少个程序,取决于该应用的设计。

2:Services services 服务是android中一个在后台运行的应用程序,没有可视化的用户界面。 例如:你可以在使用一个用户程序的同时播放背景音乐。并且此时,播放音乐的代码就不需要和用户交互,因此可以作为一个服务来运行,并且使用用户服务的接口来实现音乐的播放,暂停,等功能。对于不用向用户展示用户界面的情况下,使用服务是一个理想的选择。如同其他的组件一样,services运行于应用程序进程的主线程内。所以它不会对其他组件或用户界面有任何的妨碍,他们一般会派生一个新线程来执行一些时间消耗型的任务。

3:Broadcast receivers Broadcast receiver broadcast receiver是一个与注于接收广播通知信息并做出相应处理的组件。 许多广播是由系统代码产生的——例如通知时区改变、电池电量低、拍摄了一张 照片或者用户改变了语言选项。应用程序也可以发起广播——例如通知其它应用 程序一些数据已经下载到设备上并处于可用状态。 一个应用程序可以拥有任意数量的broadcast receiver以对所有它认为重要的 通知信息予以响应。所有的receiver均继承自BroadcastReceiver基类。broadcast receiver没有用户界面。然而它们可以启动一个activity来响应它们 收到的信息或者也可以使用NotificationManager来通知用户。通知可以用多种方式来吸引用户的注意力──闪动背光灯、震动设备、播放声音等等。通知一般是在 状态栏上放一个持续的图标用户可以打开它并获取消息。

4:Content providers 内容提供者content provider content provider将一些特定的应用程序数据供给其它应用程序使用。数据可以 存储于文件系统、SQLite数据库或其它有意义的方式。content provider继承于 ContentProvider 基类实现了一套使得其他应用程序能够检索和存储它所管理类 型数据的标准方法。然而应用程序并不直接调用返些方法而是使用一个 ContentResolver 对象调用它的方法作为替代。ContentResolver可以与任何content provider进行会话与其合作对任何相关的进程间通讯进行管理。 参阅独立的Content Providers文档以获得更多关于使用content provider的信 息。 每当出现一个需要被特定组件处理的请求时Android会确保那个组件的应用 程序进程处于运行状态必要时会启动它并确保那个组件的一个合适的实例可必 要时会创建那个实例。

激活组件

四种类型组件中的三种:活动 服务和广播接受者都通过一个叫做intent的异步消息激活。这些intents在运行时(runtime)将这些属于你的程序或不同程序的单独的组件绑定在一起(bind),你可以把这些intents看作是需要其他组件的action的messengers。

一个Intent通过一个Intent对象建立,该Intent对象定义了一个消息去激活一个特殊的组件或一种特殊的组件--一个Intent既可以明确的说明也可以不明确,要分情况来看。

对于活动和服务,一个Intent定义了一个动作去执行(比如:要View或者send什么)和要操作数据的uri,一个Intent可能传递了为一个Activity传递了一个请求去展示一张图片或者打开一个网页在这些例子中,你可以开始一个活动去接收结果,在这个例子中,这个Activity也可以返回这个通过一个Intent返回一个结果(例如,你可以发动一个Intent去让用户选择一个个人的contact并且返回给你,这个返回的意图包括一个指向这个联系人的URI)

对于广播接收者来说,intent只是简单的定义了要广播的内容(比如,一个用以表明电池电量很低的广播仅包含了一个表明电池电量很低的字符串)。

另外一个组件的类型,内容提供者,不是通过意图激活。而是由接收到contentResolver请求是激活的这个内处理者处理所有的直接的事务通过内容提供者。因此,这里有不同的方法来激活不同类型的组件,你可启动一个一个活动(或者给他一些新的要做的内容)通过传递一个Intent来startActivity () 或者startActivityForResult()(当你需要这个Activity返回一个结果时)。你可以启动一个Service(或者给一个内在的服务一些新的指令)通过传递一个Intent来startServices(),或者你可以通过把一个Intent传递给bindService()来绑定一个service。 You can initiate a broadcast by passing an Intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast(). 你可以通过传递一个Intent给诸如sendBroadcast()、sendOrderedBroadcast()或者sendStickyBroadcast()等方法来初始化一个广播。你可以通过调用ContentResolver的query()方法来执行一次content provider的查询操作。更多关于使用Intent的信息,查看Intent和IntentFilters文档。更多关于如何激活特定的组件同样在下面的文档中提供:Activities, Services, BroadcastReceiver and Content Providers. Declaring components声明组件。Manifest的首要的任务就是声明系统中有关这个应用的组件。例如,一个manifest文件可以通过声明一个Activity如下:

lt;?xml version='1.0' encoding='utf-8'?gt;

lt;manifest ... gt;

lt;application android:icon='@drawable/app_icon.png' ... gt;

lt;activity android:name='com.example.project.ExampleActivity' android:label='@string/example_label' ... gt;

lt;/activitygt;

...

lt;/applicationgt;

lt;/manifestgt;

在这个lt;applicationgt;元素中android:icon属性指向一个资源(用来表示当前这个应用程序的图标)。在lt;Activitygt; 这个元素中,android :name属性用于确定继承Activity的的子类的全路径名android:label属性用于表示这个用户可见的标签。

你必须通过一下的方法来声明这些应用组件:

lt;activitygt;标签 services:lt;servicegt;标签 broadcast receiver:lt;receivergt;标签 content providers:lt;providergt;标签。

如果你的程序中用到了活动,服务,内容提供者但是没有在manifest中声明,结果是这些组件不会被系统所知道从而不会运行。但是,broadcast Receivers 既可以在manifest中声明也可以动态的通过代码来创建(作为broadcast Receivers对象)并且使用registerReceiver()在系统中注册。就像上面说的那样,在激活组件的时候,你可以使用Intent来开始活动,服务,内容提供者。你可以明确的在Intent中声明目标组件的名称(使用组件的类名)。但是,Intent的真正的能力取决于Intent的action的概念,你可以简单的描述你要操作的动作的类型(或者是有选择的描述你要的在动作中使用的数据),并且可以允许系统找到一个在设备上组件执行和启动它。如果有多个在Intent中描述能执行动作的组件,则可以让用户去选择自己想用的。

系统识别能对Intent做出响应的方式是通过比较接收到的Intent和设备中应用程序的manifest文件中的Intent filters。当你在应用的manifest中声明一个组件时,你可以有选择的包含Intent filters,这些Intent filters表明了这些组件对其他应用程序的Intent做出反应的能力。你可以通过添加一个lt;intent-filtergt;作为 来为你的组件声明一个Intent filters,例如:一个有处理新邮件Activity的邮件应用也许可以声明一个Intent filter在它的manifest入口中来作为send Intent(为了send Email ),在你的应用中可以创建一个带有发送的Intent(action_send),当你用startactivity()调用这个Intent,系统在邮件程序中匹配一个send的Activity并且运行它,声明运行程序所需要的条件。

有多种多样的设备上运行着android系统并且不是所有的设别都提供相同的特征和能力,为了防止你的程序安装在缺乏相应功能的设备上,在你的manifest未见中声明硬件和软件的要求(为了让你的应用被不同的设备支持)变得尤为的重要。大多数这些信息和声明并不会被系统读取。但是其他的服务比如Android Market却会阅读这些声明来帮助通过通过自己的设备搜索软件的用户过滤软件。比如:你的应用需要照相和android 2.1的api,你应该在你的manifest文件中声明这些要求。通过这种方法,这些没有相机功能或者是android版本低于2.1的不能冲Google play中安装该应用。然而,你也可以在你的应用中使用相机,但是并不是需要它。在这个情况下,你的应用在运行时必须执行一次检查来确定这个设备是否有相机。如果你的设备没有相机,那么系统会使使用照相机的相关程序不可用。

在你设计和开发你的应用程序的时候,这里是一些你应该考虑的重要的设备特征 Screen size and density 屏幕尺寸和分辨率。为了对屏幕类型进行分类。Android为每个设备定义了2个重要的特征: 屏幕大小和屏幕分辨率。为了简化所有屏幕配置的不同类型,android系统把他们集中到一起去选择来更好的去瞄准,屏幕尺寸有:小 正常 大 超级大 屏幕分辨率类型:低分辨率,中分辨率,高分辨率,超高分辨率;

在默认的情况下,你的应用匹配所有的屏幕大小和分辨率,因为安卓系统面向你的ui布局和图像资源做出适当的调整。然而,你应该为确定的屏幕尺寸创建专业的布局和提供专业的图像为专门的分辨率,使用可供选择的布局资源,通过在你的manifest文件中使用lt;supports-screensgt;明确声明你的应用程序支持的屏幕大小。

输入配置:许多设备提供不同的用户输入机制,比如键盘、轨迹球、五位元导航。如果你的应用需要特别的输入硬件,你需要在你的manifest文件中用lt;uses-configurationgt;来声明。然而,需要特殊的硬件输入通常是极少的。

设备配置:有许多的硬件和软甲并不存在一个运行着android的设备上,比如照相机,光传感器,蓝牙,某个版本的openGL或者屏幕的保真度。你在任何情况下都不能假设所有的安卓设备上一定存在某种特性(除了android标准库的情况)。因此,如果你的应用使用了某features,你需要在你的manifest 中声明lt;uses-featuregt;。

平台版本:不同的android设备运行着不同的android平台,比如

全文共6939字,剩余内容已隐藏,支付完成后下载完整资料


资料编号:[8989],资料为PDF文档或Word文档,PDF文档可免费转换为Word

原文和译文剩余内容已隐藏,您需要先支付 30元 才能查看原文和译文全部内容!立即支付

以上是毕业论文外文翻译,课题毕业论文、任务书、文献综述、开题报告、程序设计、图纸设计等资料可联系客服协助查找。