第3章: 安卓应用环境外文翻译资料

 2022-01-26 09:01

Chapter 3: Android Application Environment

This chapter provides the information necessary for a reader to become familiar with an Android application environment in order to follow solutions given in the subsequent chapters. It outlines the steps needed to set up an environment, explains the fundamental concepts of Android application development, and describes a few common techniques frequently used for a Android Mobile EMU Portal implementation.

Android Environment Setup instructions

The steps on how to set up Android development environment are acquired from official Android website and are outlined below (“Installing the SDK,” n.d.).

Install Android Java Development Kit. The first step in setting up an Android development environment is to install the official Java Development Kit (JDK) from the Sun/Oracle website:

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Install Android Software Development Kit. The second step in the process involves installing the Android Software Development Kit (SDK) from Android Developers website:

http://developer.android.com/sdk/index.html

This site provides the tools and resources needed to test Android applications. Upon installation, users should verify that all the necessary components are installed via SDK Manager. The window may look like the one in Figure 1. Users need to make sure that

“Tools” section, desired versions of Android APIs and possible extras are installed. SDK

Manager is used to check for Android environment updates in the future. It is recommended to install different versions of Android APIs is because not all Android devices on the market support all SDK versions, but the application should (Murphy, 2010).

Figure 1. Android SDK Manager

Install Eclipse. The third step is to install Eclipse IDE for Java Development.

Installation files can be downloaded from the official Eclipse website:

http://www.eclipse.org/downloads/

Install Android Developer Tools plug-in. After starting the Eclipse software through the executable icon, the Android Developer Tools (ADT) plug-in needs to be installed. In order to do this, click on “Help,” then “Install new software.” In the installation dialog box, click on “Add” and paste the following URL:

https://dl-ssl.google.com/android/eclipse

Name the instance “Android” or any way preferred. Eclipse will automatically load the list of available packages, where “Developer Tools” should be checked. Continue with the installation, click “Finish” at the end, and restart Eclipse software.

Set up testing environment. The last step in the installation process is setting up an

Android Emulator for testing purposes. Felker (2011) explains how to set up an Emulator. First, start AVD Manager and create a new Android Virtual Device. In an opened window, click “New” and give this instance a name. The target option should be set up to Google APIs. Virtual memory card space can be specified that an application will operate with. Allocate enough memory to meet your application needs. When these tasks are completed, click on “Create AVD” and an emulator will be created.

To start an Emulator, select the created instance and click on “Start” from the AVD Manager window. This can be accomplished through the Eclipse window as well by clicking on Window from the main menu and then selecting AVD Manager. It will take some time until the Emulator is initialized for the first time. The process will go through two different windows until it reaches the final screen when your application can be tested. This screen looks like the one presented in Figure 2.

Figure 2. Android Emulator Screen

There is another way to test applications. It involves using a personal Android device as a debugging tool, which is an easier and faster way to navigate through an app (Steele, 2011). Android devices are preset to accept apps installed only from the Android Market, so

Table 1 describes a few steps that need to be taken care of before using this feature.

Table 1

Device Setup for Development (based on “Using Hardware Devices,” 2012)

Step

Action

1

Declare your application as 'debuggable' in your Android Manifest:

In Eclipse, you can do this from the Application tab when viewing the Manifest (on the right side, set “Debuggable” to true). Otherwise, in theAndroidManifest.xml file, add android:debuggable='true' to the lt;applicationgt; element.

2

Set up your device to allow installation of non-Market applications:

On the device, go to Settings gt; Applications and enable Unknown sources (on an Android 4.0 device, the setting is located in Settings gt; Security).

3

Turn on 'USB Debugging' on your device:

On the device, go to Settings gt; Applications gt; Development and enable USB debugging (on an Android 4.0 device, the setting is located in Settings gt; Developer options).

4

Set up your system to detect your device:

If you#39;re developing on Windows, you need to install a USB driver for adb. If you#39;re using an Android Developer Phone (ADP), Nexus One, or Nexus S, see the Google Windows USB Driver (http://developer.android.com/sdk/win-usb.html). Otherwise, you can find a link to the appropriate OEM driver from http://developer.android.com/sdk/oem-usb.html.

If you#39;re developing on Mac OS X, it just works. Skip this step.

Once the Android device driv

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


第3章: 安卓应用环境

本章提供了读者熟悉 Android 应用程序环境所需的信息,以便遵循后面章节中给出的解决方案。它概述了设置环境所需的步骤,解释了 Android 应用程序开发的基本概念,并介绍了 Android 移动 EMU 门户实现中常用的一些常用技术。

  • 安卓环境设置说明

如何设置 Android 开发环境的步骤是从 Android 官方网站上获得的,概述如下 (“安装 SDK ”,n. d.)。

安装 Android Java 开发套件。建立 Android 开发环境的第一步是从Sun/Oracle 网站安装官方 Java 开发工具包(JDK):

http://www.oracle.com/technetwork/java/javase/downloads/index.html

安装 Android 软件开发套件。此过程的第二步是从 Android 开发人员网站安装 Android 软件开发工具包(SDK):

http://developer.android.com/sdk/index.html

此网站提供了测试 Android 应用程序所需的工具和资源。安装后,用户应该验证所有必要的组件是否都是通过SDK管理器安装的。该窗口可能类似于图1中的窗口。用户需要确保“工具”部分,所需版本的Android APIs和可能的额外功能已安装。SDK 管理器用于检查将来的 Android 环境更新。建议安装不同版本的 Android APIs是因为市场上并非所有的 Android 设备都支持所有 SDK 版本,但应用程序应该支持(Murphy,2010)。

图1 安卓 SDK 管理器

安装 Eclipse。第三步是为 Java 开发安装 eclipse IDE。安装文件可以从 Eclipse 官方网站下载:

http://www.eclipse.org/downloads/

安装 Android 开发人员工具插件。通过可执行图标启动 eclipse 软件后,需要安装 Android 开发工具 (ADT) 插件。要做到这一点, 点击“帮助”,然后点击“安装新软件”。在安装对话框中,单击“添加”并粘贴以下 URL:

https://dl-ssl.google.com/android/eclipse

将实例命名为“Android”或任何首选方式。Eclipse 将自动加载可用包的列表,其中应选上“开发人员工具”。继续安装,单击末尾的“完成”, 然后重新启动 Eclipse 软件。

设置测试环境。安装过程中的最后一步是设置用于测试目的的 Android 仿真器。Felker (2011)解释了如何设置仿真程序。首先,启动 AVD 管理器并创建一个新的 Android 虚拟设备。在打开的窗口中,单击“新建”并为此实例指定名称。目标选项应设置为 Google APIs。可以指定应用程序将使用的虚拟存储卡空间。分配足够的内存以满足您的应用程序需求。完成这些任务后,点击“创建 AVD”,将创建一个仿真器。

要启动仿真程序,请选择创建的实例,然后从 AVD 管理器窗口中单击“开始”。这可以通过 Eclipse 窗口来实现,也可以通过单击主菜单中的 “窗口”,然后选择 AVD 管理器来实现。第一次初始化仿真程序需要一些时间。该过程将通过两个不同的窗口,直到它到达最终屏幕,这时您的应用程序可以进行测试。此屏幕类似于图2中显示的屏幕。

图2 安卓仿真器屏幕

还有另一种方法来测试应用程序。它涉及使用个人 Android 设备作为调试工具,这是一种更容易、更快捷的浏览应用程序的方式(Steele,2011年)。Android 设备被预设为接受仅从 Android 市场安装的应用程序,因此表1描述了在使用此功能之前需要注意的几个步骤。

表1:用于开发的设备设置 (基于“使用硬件设备”,2012年)

步骤

做法

1

在 Android Manifest文件中声明您的应用程序为“可调试”:

在 Eclipse 中,您可以在查看Manifest时从“应用程序”选项卡执行此操作(在右侧,将“可调试”设置为 true)。否则,在AndroidManifest.xml 文件中,将android:debuggable='true' 添加到 lt; application gt; 元素中。

2

设置您的设备以允许安装非市场应用程序:

在设备上,转到 “设置” gt; “应用程序并启用未知源”(在 Android 4.0 设备上,该设置位于 “设置” gt; “安全性中”)。

3

打开设备上的“USB 调试”:

在设备上,转到“设置”gt; “应用程序” gt; “开发”,并启用 USB 调试(在 Android 4.0 设备上,该设置位于“设置” gt; “开发人员选项中”)。

4

设置系统以检测设备:

如果您在 Windows 上开发,则需要为 adb 安装 USB 驱动程序。如果您使用的是 Android 开发人员电话 (ADP),Nexus One或 Nexus S,请参阅 Google Windows USB 驱动程序(http://developer.android.com/sdk/win-usb.html)。如果以上都不是,您可以从 http://developer.android.com/sdk/oem-usb.html 找到指向相应 OEM 驱动程序的链接。如果您在 Mac OS X 上进行开发,它就能正常工作。跳过此步骤。

一旦在计算机上安装了 Android 设备驱动程序,Eclipse 将在手机通过 USB 连接插入时识别它。当开发人员运行应用程序时,他或她将看到类似于图3中的屏幕。

图3 安卓设备选择器

选择 Android 设备后,Eclipse 将在其上安装文件,开发人员将能够直接在手机上测试应用程序。

  • 安卓应用程序文件结构

Android 应用有一组文件夹,其中包含它们使用的资源。通过单击“文件”,然后单击“新建”,然后单击“项目”(Murphy,2010年),在 Eclipse 中启动一个 Android 项目。从 Android 组中选择“Android 项目”后,按照向导步骤输入项目、包和主要活动名称,并在完成后开始开发。每个应用的结构都是相同的,图4给出了它的一般概述。

图4 安卓应用程序文件结构

此层次结构的顶部是项目文件夹,它为应用程序提供工作区。Eclipse 中的自动调试将提供有关应用程序中出现的错误的实时更新,并进一步钻取到结构中,以指出包含错误的特定资源。这些将被标记为红色的“X”图标。Felker (2011)概述了文件夹结构,可以这样描述:

  • “src”文件夹包含类和包。这就是AndroidManifest.xml文件将引用它们的地方。
  • “gen”文件夹存储有关所有视图和小部件的自动生成的标识数据,这些视图和小部件提供可在屏幕上看到的信息。不应该手动更改此文件夹的内容。
  • “Android”文件夹包含有关用于该应用程序的目标 Android 库的数据。
  • “assets”文件夹存储应用正在使用的任何其他数据。
  • “bin”文件夹包含调试后创建的数据,如安装在实际设备上的项目. apk 文件以及有关所使用资源的信息。
  • “res”文件夹存储不同的应用资源。最常见的情况是,此文件夹用于引用“布局”子文件夹中的 XML 布局或图标的不同图像。

AndroidManifest.xml 文件是 Android 应用程序文件结构中最重要的文件。 Felker (2011)指出,该文件“跟踪应用程序所需、请求和必须使用才能运行的所有内容。”它的一些功能包括提供有关可用活动、服务和使用的权限的信息, 或 Android API 级别要求。

  • 活动

活动是与用户交互的包中的类 (“Activity”,2012年)。这些类扩展了 “Activity”类型,从而继承了成功实施 Android 应用所需的方法和其他相关信息。表2显示了活动可以在中,具体取决于用户与该活动的交互。图5描述了活动可以采用的状态路径。根据 Android 开发人员的官方网站,在此图中,方框形矩形表示了活动在状态之间切换移动时可以实现执行操作的相应回调方法(“ Activity ”,2012年),彩色椭圆形是活动可以处于的主要状态(“ Activity ”,2012年)。下面介绍了初始化活动的步骤。

表2:活动状态(基于“Activity ”,2012年)

状态

描述

1

如果活动位于屏幕前景中(位于堆栈顶部),则该活动处于活动状态或正在运行状态。

2

如果某个活动失去了焦点,但仍然可见(即新的非全尺寸或透明活动的重点放在您的活动之上),则该活动将暂停。暂停的活动是完全有效的(它维护所有状态和成员信息,并保持附加到窗口管理器),但在极端内存不足的情况下可能会被系统杀死。

3

如果一个活动被另一个活动完全掩盖,它将被停止。它仍然保留所有状态和成员信息。但是,它不再是可见的用户,因此它的窗口是隐藏的。它往往会在其他地方需要内存时被系统杀死。

4

如果活动暂停或停止,系统可以通过要求它完成或简单地终止其进程来从内存中删除该活动。当它再次显示给用户时,它必须完全重新启动并恢复到以前的状态。

图5 活动生命周期 (“Activity”,2012)

定义活动。假设通过安卓应用程序文件结构这一节的第一段落的步骤初始化了新的 android 项目,则必须在AndroidManifest.xml(“Activity ”,2012年)中定义活动。可以通过在Manifest文件里的lt;applicationgt;标签内复制以下代码来引入活动:

lt;activity android:label='@string/app_name' android:name='test.project.TestActivity' gt;lt;/activitygt;

设置应用程序启动时启动的活动。活动之一是在应用程序启动时打开的 “启动器”活动。此信息将在创建第一个活动时自动生成。如果希望有一个不同的 “启动器”,可以通过复制以下代码写入到活动的lt;activitygt;标签里。

lt;intent-filtergt;lt;action android:name='android.intent.action.MAIN' /gt;

lt;category android:name='android.intent.category.LAUNCHER' /gt;lt;/intent-filtergt;

  • Intents

活动可以使用 Intents相互交流。Intents是活动之间共享的“信息”(Felker,2011年)。每个Intents都可以存储各种类型的信息并将其传递给另一个活动。除了发送变量外,开发人员还可以通过关闭或保持活动打开状态来控制当前的活动操作。

下面的步骤将介绍活动使用的方法,以便通过 Intents以相互通信。

启动一个Intent。为了能够启动一个Intent,可以在发送信息的类中实现以下代码行(Felker,2011年):

Intent i = new Intent(this, Target_Activity.class);

i.put

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


资料编号:[507]

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

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