版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 application fundamentals android applications are written in the java programming language. the compiled java code along with any data and resource files required by the application is bundled by the aapt tool into an android package, an archive file marked by an .apk suffix. this file is the vehic
2、le for distributing the application and installing it on mobile devices; its the file users download to their devices. all the code in a single .apk file is considered to be one application. android应用基础:android应用程序是通过java语言开发的,通过绑定一些应用所需要的东西,例如:编译的java代码,加上数据和一些资源文件,使用一个apt的工具将所有的东西封装成一个android包,这个文
3、件的文件后缀是.apk。这个文件是分发并安装应用程序到移动设备的载体,是用户获得该应用程序所需要的下载的文件。application components a central feature of android is that one application can make use of elements of other applications (provided those applications permit it). for example, if your application needs to display a scrolling list of images and
4、another application has developed a suitable scroller and made it available to others, you can call upon that scroller to do the work, rather than develop your own. your application doesnt incorporate the code of the other application or link to it. rather, it simply starts up that piece of the othe
5、r application when the need arises. for this to work, the system must be able to start an application process when any part of it is needed, and instantiate the java objects for that part. therefore, unlike applications on most other systems, android applications dont have a single entry point for e
6、verything in the application (no main() function, for example). rather, they have essential components that the system can instantiate and run as needed. there are four types of components: activities an activity presents a visual user interface for one focused endeavor the user can undertake. for e
7、xample, an activity might present a list of menu items users can choose from or it might display photographs along with their captions. a text messaging application might have one activity that shows a list of contacts to send messages to, a second activity to write the message to the chosen contact
8、, 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
9、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.
10、 moving from one activity to another is accomplished by having the current activity start the next one. android有四大应用程序组件android的一个很重要的中心特征就是一个应用程序能充分利用其他的应用程序的一些组件(前提是被允许的) 例如:如果的当前开发的应用需要一个滚动的列表去展示相片并且当时其他的程序已经开发了一个合适的滚动列表并且对其他人可用,你可以调用这个滚动的列表来完成你的工作而不是开发你自己的。你的应用不需要包含那个应用的代码或来链接它。相反,它只是简单的在你需要它是启动
11、这部分的应用为了实现这部分的功能,当前系统必须能启动其他应用程序进程的功能当那些部分它需要时,并且为这部分的java对象初始化这个java对象。因此,不想在其他系统中的应用程序,android应用程序不需要一个单一的入口点(例如:没有main()而是,提供了实例化和运行所需的必备组件。android有四大应用程序组件1:activity一个activity基类是为展示可视化用户接口。例如:一个activity可以显示一个供用户选择的菜单列表,或者可以展示一些图片以及对应的说明。一个短信的应用有一个活动显示发送消息的一系列的联系人,第二个活动去编写信息文本去选择联系人,第三个活动去查看以前的信息
12、或修改一些设置。虽然它们组成了一个内聚的用户界面,每一个活动都和其他的的相互独立,每一个都继承activity,是activity的子类。一个应用程序可以只有一个activity,但是也可以有多个,比如刚刚提到的文本应用。每个程序的作用,有多少个程序,取决于该应用的设计。servicesa service doesnt have a visual user interface, but rather runs in the background for an indefinite period of time. for example, a service might play backgro
13、und 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. 2:services服务是android中一个在后台运行的应用程序,没有可视化的用户界面。例如:你可以在使用一个用户程序的同时播放背景音乐。并且此时,播放音乐的代码就不需要和用户交互,因
14、此可以作为一个服务来运行,并且使用用户服务的接口来实现音乐的播放,暂停,等功能。对于不用向用户展示用户界面的情况下,使用服务是一个理想的选择。如同其他的组件一样,services运行于应用程序进程的主线程内。所以它不会对其他组件或用户界面有任何的妨碍,他们一般会派生一个新线程来执行一些时间消耗型的任务。broadcast receivers a broadcast receiver is a component that does nothing but receive and react to broadcast announcements. many broadcasts originat
15、e 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
16、 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 ac
17、tivity in response to the information they receive, or they may use the notificationmanager to alert the user. notifications can get the users 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,
18、 which users can open to get the3:broadcast receiverbroadcast receiver是一个与注于接收广播通知信息并做出相应处理的组件。许多广播是由系统代码产生的例如通知时区改变、电池电量低、拍摄了一张照片或者用户改变了语言选项。应用程序也可以发起广播例如通知其它应用程序一些数据已经下载到设备上并处于可用状态。 一个应用程序可以拥有任意数量的broadcast receiver以对所有它认为重要的通知信息予以响应。所有的receiver均继承自broadcastreceiver基类。 broadcast receiver没有用户界面。然而它
19、们可以启动一个activity来响应它们收到的信息或者也可以使用notificationmanager来通知用户。通知可以用多种方式来吸引用户的注意力闪动背光灯、震动设备、播放声音等等。通知一般是在状态栏上放一个持续的图标用户可以打开它并获取消息。content providers a content provider makes a specific set of the applications data available to other applications. the data can be stored in the file system, in an sqlite data
20、base, 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 u
21、se 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 thats involved. see the separate content providers document for more information on using content providers. whenever
22、 theres 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. 4:内容提供者content providerconten
23、t provider将一些特定的应用程序数据供给其它应用程序使用。数据可以存储于文件系统、sqlite数据库或其它有意义的方式。content provider继承于contentprovider 基类实现了一套使得其他应用程序能够检索和存储它所管理类型数据的标准方法。然而应用程序并不直接调用返些方法而是使用一个 contentresolver 对象调用它的方法作为替代。contentresolver可以与任何content provider进行会话与其合作对任何相关的进程间通讯进行管理。 参阅独立的content providers文档以获得更多关于使用content provider的信息
24、。 每当出现一个需要被特定组件处理的请求时android会确保那个组件的应用程序进程处于运行状态必要时会启动它并确保那个组件的一个合适的实例可必要时会创建那个实例。activating components激活组件three of the four component typesactivities, services, and broadcast receiversare activated by an asynchronous message called anintent. intents bind individual components to each other at runti
25、me (you can think of them as the messengers that request an action from other components), whether the component belongs to your application or another.四种类型组件中的三种:活动 服务和广播接受者都通过一个叫做intent的异步消息激活。这些intents在运行时(runtime)将这些属于你的程序或不同程序的单独的组件绑定在一起(bind),你可以把这些intents看作是需要其他组件的action的messengers。an intent
26、is created with anintentobject, which defines a message to activate either a specific component or a specifictypeof componentan intent can be either explicit or implicit, respectively.一个intent通过一个intent对象建立,该intent对象定义了一个消息去激活一个特殊的组件或一种特殊的组件-一个intent既可以明确的说明也可以不明确,要分情况来看for activities and services,
27、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 pag
28、e. in some cases, you can start an activity to receive a result, in which case, the activity also returns the result in anintent(for example, you can issue an intent to let the user pick a personal contact and have it returned to youthe return intent includes a uri pointing to the chosen contact).对于
29、活动和服务,一个intent定义了一个动作去执行(比如:要view或者send什么)和要操作数据的uri,一个intent可能传递了为一个activity传递了一个请求去展示一张图片或者打开一个网页在这些例子中,你可以开始一个活动去接收结果,在这个例子中,这个activity也可以返回这个通过一个intent返回一个结果(例如,你可以发动一个intent去让用户选择一个个人的contact并且返回给你,这个返回的意图包括一个指向这个联系人的uri)for broadcast receivers, the intent simply defines the announcement being
30、broadcast (for example, a broadcast to indicate the device battery is low includes only a known action string that indicates battery is low).对于广播接收者来说,intent只是简单的定义了要广播的内容(比如,一个用以表明电池电量很低的广播仅包含了一个表明电池电量很低的字符串)。the other component type, content provider, is not activated by intents. rather, it is act
31、ivated when targeted by a request from acontentresolver. the content resolver handles all direct transactions with the content provider so that the component thats performing transactions with the provider doesnt need to and instead calls methods on thecontentresolverobject. this leaves a layer of a
32、bstraction between the content provider and the component requesting information (for security).另外一个组件的类型,内容提供者,不是通过意图激活。而是由接收到contentresolver请求是激活的这个内处理者处理所有的直接的事务通过内容提供者。因此,there are separate methods for activating each type of component:这里有不同的方法来激活不同类型的组件 you can start an activity (or give it som
33、ething new to do) by passing anintenttostartactivity()orstartactivityforresult()(when you want the activity to return a result). 你可启动一个一个活动(或者给他一些新的要做的内容)通过传递一个intent来startactivity () 或者startactivityforresult()(当你需要这个activity返回一个结果时) you can start a service (or give new instructions to an ongoing se
34、rvice) by passing anintenttostartservice(). or you can bind to the service by passing anintenttobindservice().你可以启动一个service(或者给一个内在的服务一些新的指令)通过传递一个intent来startservices(),或者你可以通过把一个intent传递给bindservice()来绑定一个service。 you can initiate a broadcast by passing anintentto methods likesendbroadcast(),send
35、orderedbroadcast(), orsendstickybroadcast().你可以通过传递一个intent给诸如sendbroadcast()、sendorderedbroadcast()或者sendstickybroadcast()等方法来初始化一个广播。 you can perform a query to a content provider by callingquery()on acontentresolver.你可以通过调用contentresolver的query()方法来执行一次contentprovider的查询操作。for more information ab
36、out using intents, see theintents and intent filtersdocument. more information about activating specific components is also provided in the following documents:activities,services,broadcastreceiverandcontent providers. 更多关于使用intent的信息,查看intent和intentfilters文档。更多关于如何激活特定的组件同样在下面的文档中提供:activities,serv
37、ices,broadcastreceiverandcontent providers. declaring components声明组件the primary task of the manifest is to inform the system about the applications components. for example, a manifest file can declare an activity as follows:manifest的首要的任务就是声明系统中有关这个应用的组件。例如,一个manifest文件可以通过声明一个activity如下: . in theel
38、ement, theandroid:iconattribute points to resources for an icon that identifies the application.在这个元素中android:icon属性指向一个资源(用来表示当前这个应用程序的图标)in theelement, theandroid:nameattribute specifies the fully qualified class name of theactivitysubclass and theandroid:labelattributes specifies a string to use
39、as the user-visible label for the activity.在 这个元素中,android :name属性用于确定继承activity的的子类的全路径名android:label属性用于表示这个用户可见的标签 you must declare all application components this way:你必须通过一下的方法来声明这些应用组件l elements for activitiesl elements for servicesl elements for broadcast receiversl elements for content provi
40、dersactivities:标签services:标签broadcastreceiver:标签contentproviders:标签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
41、 manifest or created dynamically in code (asbroadcastreceiverobjects) and registered with the system by callingregisterreceiver().如果你的程序中用到了活动,服务,内容提供者但是没有在manifest中声明,结果是这些组件不会被系统所知道从而不会运行。但是,broadcast receivers 既可以在manifest中声明也可以动态的通过代码来创建(作为broadcast receivers对象)并且使用registerreceiver()在系统中注册 decla
42、ring component capabilities声明组件的能力as discussed above, inactivating components, you can use anintentto start activities, services, and broadcast receivers. you can do so by explicitly naming the target component (using the component class name) in the intent. however, the real power of intents lies i
43、n the concept of intent actions. with intent actions, you simply describe the type of action you want to perform (and optionally, the data upon which youd like to perform the action) and allow the system to find a component on the device that can perform the action and start it. if there are multipl
44、e components that can perform the action described by the intent, then the user selects which one to use.就像上面说的那样,在激活组件的时候,你可以使用intent来开始活动,服务,内容提供者。你可以明确的在intent中声明目标组件的名称(使用组件的类名)。但是,intent的真正的能力取决于intent的action的概念,你可以简单的描述你要操作的动作的类型(或者是有选择的描述你要的在动作中使用的数据),并且可以允许系统找到一个在设备上组件执行和启动它。如果有多个在intent中描述能
45、执行动作的组件,则可以让用户去选择自己想用的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.系统识别能对intent做出响应的方式是通过比较接收到的intent和设备中应用程序的manifest文件中的intent filterswhen you dec
46、lare a component in your applications manifest, you can optionally include intent filters that declare the capabilities of the component so it can respond to intents from other applications. you can declare an intent filter for your component by adding anelement as a child of the components declarat
47、ion element.当你在应用的manifest中声明一个组件时,你可以有选择的包含intent filters,这些intent filters表明了这些组件对其他应用程序的intent做出反应的能力。你可以通过添加一个作为 来为你的组件声明一个intent filtersfor example, an email application with an activity for composing a new email might declare an intent filter in its manifest entry to respond to send intents (in
48、 order to send email). an activity in your application can then create an intent with the “send” action (action_send), which the system matches to the email applications “send” activity and launches it when you invoke the intent withstartactivity().例如:一个有处理新邮件activity的邮件应用也许可以声明一个intent filter在它的man
49、ifest入口中来作为send intent(为了send email ),在你的应用中可以创建一个带有发送的intent(action_send),当你用startactivity()调用这个intent,系统在邮件程序中匹配一个send的activity并且运行它for more about creating intent filters, see theintents and intent filtersdocument.declaring application requirements声明运行程序所需要的条件there are a variety of devices powered
50、 by android and not all of them provide the same features and capabilities. in order to prevent your application from being installed on devices that lack features needed by your application, its important that you clearly define a profile for the types of devices your application supports by declar
51、ing device and software requirements in your manifest file. most of these declarations are informational only and the system does not read them, but external services such as google play do read them in order to provide filtering for users when they search for applications from their device.有多种多样的设备
52、上运行着android系统并且不是所有的设别都提供相同的特征和能力,为了防止你的程序安装在缺乏相应功能的设备上,在你的manifest未见中声明硬件和软件的要求(为了让你的应用被不同的设备支持)变得尤为的重要。大多数这些信息和声明并不会被系统读取。但是其他的服务比如androidmarket却会阅读这些声明来帮助通过通过自己的设备搜索软件的用户过滤软件。for example, if your application requires a camera and uses apis introduced in android 2.1 (api level7), you should declar
53、e these as requirements in your manifest file. that way, devices that donothave a camera and have an android versionlowerthan 2.1 cannot install your application from google play.比如:你的应用需要照相和android 2.1的api,你应该在你的manifest文件中声明这些要求。通过这种方法,这些没有相机功能或者是android版本低于2.1的不能冲google play中安装该应用however, you can
54、 also declare that your application uses the camera, but does notrequireit. in that case, your application must perform a check at runtime to determine if the device has a camera and disable any features that use the camera if one is not available.然而,你也可以在你的应用中使用相机,但是并不是需要它。在这个情况下,你的应用在运行时必须执行一次检查来确
55、定这个设备是否有相机。如果你的设备没有相机,那么系统会使使用照相机的相关程序不可用here are some of the important device characteristics that you should consider as you design and develop your application:在你设计和开发你的应用程序的时候,这里是一些你应该考虑的重要的设备特征screen size and density屏幕尺寸和分辨率in order to categorize devices by their screen type, android defines tw
56、o characteristics for each device: screen size (the physical dimensions of the screen) and screen density (the physical density of the pixels on the screen, or dpidots per inch). to simplify all the different types of screen configurations, the android system generalizes them into select groups that make them easier to target.为了对屏幕类型进行分类。android为每个设备定义了2个重要的特征:屏幕大小和屏幕分辨率。为了简化所有屏幕配置的不同类型,android系统把他们集中到一起去选择来更好的去瞄准the screen sizes are: small, normal, large, and extra large.the screen densities are: low density, medium density, h
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 马鞍山职业技术学院《艺术形态采集课程设计》2023-2024学年第一学期期末试卷
- 吕梁学院《成本会计模拟》2023-2024学年第一学期期末试卷
- 2024年临时活动场地租赁合同范本
- 2025年南宁货车资格证试题及答案
- 2024年个人担保书填写说明3篇
- 2024年上门女婿财产分割及婚姻关系解除协议书3篇
- 洛阳文化旅游职业学院《池塘养殖学A》2023-2024学年第一学期期末试卷
- 2024年水利工程劳务分包协议样本
- 单位人事管理制度精彩选集
- 办公物业招投标攻略流程掌握
- GB/T 16947-2009螺旋弹簧疲劳试验规范
- 圣诞节开幕词(3篇)
- GA/T 1312-2016法庭科学添改文件检验技术规程
- FZ/T 64041-2014熔喷纤网非织造粘合衬
- 多场耦合完整版资料课件
- 2022年勿忘国耻吾辈自强纪念12.13国家公祭日PPT
- 第二代测序技术-新一代基因组测序技术原理及应用课件
- 重医大临床麻醉学教案23腹部外科与泌尿外科手术的麻醉
- 六年级上册数学课件-6.13 稍复杂的百分数实际问题丨苏教版 (共18张PPT)
- 物理化学课件第8章表面化学
- 脑卒中诊疗、护理与防治考核题库与答案
评论
0/150
提交评论