一、Introduction(入门)
0、Introduction to Android(引进到Android)
Android provides a rich application framework that allows you to build innovative apps and games for mobile devices in a Java language environment. The documents listed in the left navigation provide details about how to build apps using Android's various APIs.To learn how apps work, start
with App Fundamentals.
To begin coding right away, read Building Your First App
Android提供了丰富的应用程序框架,它允许您在Java语言环境中构建移动设备的创新应用程序和游戏。在左侧导航中列出的文档提供了有关如何使用Android的各种API来构建应用程序的详细信息。要了解如何开发应用,从应用基础开始。
如何开始一个正确的编码,请参照建立你的第一个应用程序。
Apps provide multiple entry points 应用程序提供多个入口点Apps adapt to different devices 应用程序适应不同的设备
Android apps are built as a combination of distinct components that can be invoked individually. For instance, an individual activity provides a single screen for a user interface, and a service independently performs work in the background.
Android应用程序被构建为能够单独地被调用不同的部件的组合。例如,一个单独的Activity 提供了一个单个屏幕上的用户界面,和一个Service独立地在后台中执行工作。Android provides an adaptive app framework that allows you to provide unique resources for different device configurations. For example, you can create different XML layout files for different screen sizes and the system determines which layout to apply based on the current device's screen size.
Android提供了一个自适应的应用程序框架,它允许您为不同的设备配置提供不同的资源。例如,您可以为不同的屏幕尺寸创建不同的XML布局文件并且系统决定了基于当前屏幕尺寸使用哪些布局。
From one component you can start another component using an intent. You can even start a component in a different app, such an activity in a maps app to show an address. This model provides multiple entry points for a single app and allows any app to behave as a user's "default" for an action that other apps may invoke. You can query the availability of device features at runtime if any app features require specific hardware such as a camera. If necessary, you can also declare feat
ures your app requires so app markets such as Google Play Store do not allow installation on devices that do not support that feature.
从一个组件就可以使用一个Intent 启动另一个
组件。你甚至可以启动不同应用程序中的一个
组件,比如启动一个地图应用中的Activity 来
显示地址。该模型为一个单一的应用程序提供了多个入口点,并允许任何应用程序的行为作
为用户的“默认”,用于其他应用程序调用的
Action
你可以在运行时查询设备功能的可用性,如果任何应用程序的功能需要特定的硬件如照相机。如果需要,你也可以定义你的应用程序需要的特性,,如Google Play 商店不允许不支持该特性的设备安装。 Learn more:
∙
App Fundamentals ∙
Intents and Intent Filters ∙ Activities 了解更多: ∙
应用基础 ∙
意图和意图过滤器 ∙ Activities
Learn more: ∙ Device Compatibility ∙ Resources Overview ∙
User Interface Overview
了解更多: ∙ 设备兼容性 ∙ 资源概述 ∙ 用户界面概述
1、Application Fundamentals(应用程序基础) Android apps are written in the Java programming language. The Android SDK tools compile your
code —along with any data and resource files —
into an APK: an Android package , which is an
archive file with an .apk suffix. One APK file contains all the contents of an Android app and is
the file that Android-powered devices use to install
the app.
Android 应用程序是用Java 写的。Android SDK
工
具编译你的代码以及任何数据和资源文件为APK :
一个Android 包,这是一个以.apk 为后缀的存档文
件。一个APK 文件包含了一个Android 应用程序
的所有内容,是Android 平台的设备应用程序的安
装文件。
Once installed on a device, each Android app lives
in its own security sandbox:
一旦安装在设备上,每个Android
应用程序存在于它自己的安全沙箱中:
∙The Android operating system is a multi-user Linux system in which each app is a different user.
Android是一个多用户的Linux操作系统,每一个应用都是一个不同的用户。
∙By default, the system assigns each app a unique Linux user ID (the ID is used only by the system and is unknown to the app). The system sets permissions for all the files in an app so that only the user ID assigned to that app can access them.
默认情况下,系统关联每一个应用程序到不同的Linux用户Id(这个ID只被系统使用,应用程序是不知道的)。系统设置一个应用程序中的所有文件的权限,以便仅仅此应用程序的用户ID可以访问它们。
∙Each process has its own virtual machine (VM), so an app's code runs in isolation from other apps.
每一个进程都有他自己的虚拟机(VM),所以应用程序的代码的运行独立于其他应用程序。
∙By default, every app runs in its own Linux process. Android starts the process when any of the app's components need to be executed, then shuts down the process when it's no longer needed or when the system must recover memory for other apps.
默认情况下,每一个应用程序运行在他自己的Linux进程。当任何任用程序的祖先需要被执行的时候,Android启动这个程序的进程;当它不再需要时或系统必须恢复内存的其他应用程序,关闭该进程。
In this way, the Android system implements the principle of least privilege. That is, each app, by default, has access only to the components that it requires to do its work and no more. This creates a very secure environment in which an app cannot access parts of the system for which it is not given permission.
在这种方式中,Android系统实现了最小特权原则。也就是说,每个应用程序,默认情况下,只能访问到它的工作所需要的最少的权限。这将创建一个非常安全地环境:每一个应用程序不能访问系统没有给予它权限的任何一个部分。
However, there are ways for an app to share data with other apps and for an app to access system services:
然而,有办法让一个应用程序与其他应用程序共享数据,一个应用程序可以访问系统服务:∙It's possible to arrange for two apps to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, apps with the same user ID can also arrange to run in the same Linux process and share the same VM (the apps must also be signed with the same certificate).
它可以让两个应用程序共享相同的Linux用户ID,在这种情况下,他们能够访问对方的文件。为了节省系统资源,应用程序使用相同的用户ID也可以运行在同一个Linux进程中,并共享相同的VM(并且应用程序也必须使用相同的证书签名)。
∙An app 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 app permissions must be granted by the user at install time.
一个应用程序能够请求权限去访问设备上的数据,比如用户的联系人信息、短信、
SDCard、照相机、蓝牙等等。所有的应用程序权限必须在用户安装软件的时候给予授权。
That covers the basics regarding how an Android app exists within the system. The rest of this document introduces you to:
这包括关于一个Android应用程序怎样存在于系统中存在的基本知识。本文档的其余部分向您介绍:
∙The core framework components that define your app.
定义您应用程序的的核心框架组件
∙The manifest file in which you declare components and required device features for your app.
android权威编程指南在您的应用程序Manifest文件中声明组件和所需设备功能
∙Resources that are separate from the app code and allow your app to gracefully optimize its behavior for a variety of device configurations.
资源是独立于应用程序代码的,让你的应用程序,以优雅地行为为各种设备优化配置。
1.1、App Components(应用程序组件)
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 Activities developer 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
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论