安卓应用开发中英文对照外文翻译文献

合集下载

关于Android的外文文献

关于Android的外文文献

附件A 外文文献(英文)Android: A Programmer’s Guide1 What Is Android1.1 Key Skills & Concepts●History of embedded device programming●Explanation of Open Handset Alliance●First look at the Android home screenIt can be said that, for a while, traditional desktop application developers have been spoiled. This is not to say that traditional desktop application development is easier than other forms of development. However, as traditional desktop application developers, we have had the ability to create almost any kind of application we can imagine. I am including myself in this grouping because I got my start in desktop programming.One aspect that has made desktop programming more accessible is that we have had the ability to interact with the desktop operating system, and thus interact with any underlying hardware, pretty freely (or at least with minimal exceptions). This kind of freedom to program independently, however, has never really been available to the small group of programmers who dared to venture into the murky waters of cell phone development.NOTE :I refer to two different kinds of developers in this discussion: traditional desktop application developers, who work in almost any language and whose end product, applications, are built to run on any “desktop” operating system; and Android developers, Ja va developers who develop for the Android platform. This is not for the purposes of saying one is by any means better or worse than the other. Rather, the distinction is made for purposes of comparing the development styles and tools of desktop operating system environments to the mobile operating system environment,1.2 Brief History of Embedded Device ProgrammingFor a long time, cell phone developers comprised a small sect of a slightly larger group of developers known as embedded device developers. Seen as a less “glamorous” sibling to desktop—and later web—development, embedded device development typically got the proverbial short end of the stick as far as hardware and operating system features, because embedded device manufacturers were notoriously stingy on feature support.Embedded device manufacturers typically needed to guard their hardware secrets closely, so they gave embedded device developers few libraries to call when trying to interact with a specific device. Embedded devices differ from desktops in that an embedded device is typically a “computer on a chip.” For example, consider your standard television remote control; it is not really seen as an overwhelming achievement of technological complexity. When any button is pressed, a chip interprets the signal in a way that has been programmed into the device. This allows the device to know what to expect from the input device (key pad), and how to respond to those commands (for example, turn on the television). This is a simple form of embedded device programming. However, believe it or not, simple devices such as these are definitely related to the roots of early cell phone devices and development.Most embedded devices ran (and in some cases still run) proprietary operating systems. The reason for choosing to create a proprietary operating system rather than use any consumer system was really a product of necessity. Simple devices did not need very robust and optimized operating systems.As a product of device evolution, many of the more complex embedded devices, such as early PDAs, household security systems, and GPSs, moved to somewhat standardized operating system platforms about five years ago. Small-footprint operating systems such as Linux, or even an embedded version of Microsoft Windows, have become more prevalent on many embedded devices. Around this time in device evolution, cell phones branched from other embedded devices onto their own path. This branching is evident when you examine their architecture.Nearly since their inception, cell phones have been fringe devices insofar as they run on proprietary software—software that is owned and controlled by the manufacturer, and is almostalways considered to be a “closed” system. The practice of manufacturers using proprietar y operating systems began more out of necessity than any other reason. That is, cell phone manufacturers typically used hardware that was completely developed in-house, or at least hardware that was specifically developed for the purposes of running cell phone equipment. As a result, there were no openly available, off-the-shelf software packages or solutions that would reliably interact with their hardware. Since the manufacturers also wanted to guard very closely their hardware trade secrets, some of which could be revealed by allowing access to the software level of the device, the common practice was, and in most cases still is, to use completely proprietary and closed software to run their devices. The downside to this is that anyone who wanted to develop applications for cell phones needed to have intimate knowledge of the proprietary environment within which it was to run. The solution was to purchase expensive development tools directly from the manufacturer. This isolated many of the “homebrew” devel opers.NOTE:A growing culture of homebrew developers has embraced cell phone application development. The term “homebrew” refers to the fact that these developers typically do not work for a cell phone development company and generally produce small, one-off products on their own time.Another, more compelling “necessity” that kept cell phone development out of the hands of the everyday developer was the hardware manufacturers’ solution to the “memory versus need” dilemma. Until recently, cell phon es did little more than execute and receive phone calls, track your contacts, and possibly send and receive short text messages; not really the “Swiss army knives” of technology they are today. Even as late as 2002, cell phones with cameras were not commonly found in the hands of consumers.By 1997, small applications such as calculators and games (Tetris, for example) crept their way onto cell phones, but the overwhelming function was still that of a phone dialer itself. Cell phones had not yet become the multiuse, multifunction personal tools they are today. No one yet saw the need for Internet browsing, MP3 playing, or any of the multitudes of functions we are accustomed to using today. It is possible that the cell phone manufacturers of 1997 did not fully perceive the need consumers would have for an all-in-one device. However, even if the need was present, a lack of device memory and storage capacity was an even biggerobstacle to overcome. More people may have wanted their devices to be all-in-one tools, but manufacturers still had to climb the memory hurdle.To put the problem simply, it takes memory to store and run applications on any device, cell phones included. Cell phones, as a device, until recently did not have the amount of memory avail able to them that would facilitate the inclusion of “extra” programs. Within the last two years, the price of memory has reached very low levels. Device manufacturers now have the ability to include more memory at lower prices. Many cell phones now have more standard memory than the average PC had in the mid-1990s. So, now that we have the need, and the memory, we can all jump in and develop cool applications for cell phones around the world, right? Not exactly.Device manufacturers still closely guard the operating systems that run on their devices. While a few have opened up to the point where they will allow some Java-based applications to run within a small environment on the phone, many do not allow this. Even the systems that do allow some Java apps to run do not allow the kind of access to the “core” system that standard desktop developers are accustomed to having.1.3 Open Handset Alliance and AndroidThis barrier to application development began to crumble in November of 2007 when Google, under the Open Handset Alliance, released Android. The Open Handset Alliance is a group of hardware and software developers, including Google, NTT DoCoMo, Sprint Nextel, and HTC, whose goal is to create a more open cell phone environment. The first product to be released under the alliance is the mobile device operating system, Android. (For more information about the Open Handset Alliance, see .)NOTE :Google, in promoting the new Android operating system, even went as far as to create a $10 million contest looking for new and exciting Android applications.While cell phones running Linux, Windows, and even PalmOS are easy to find, as of this writing, no hardware platforms have been announced for Android to run on. HTC, LG Electronics, Motorola, and Samsung are members of the Open Handset Alliance, under which Android has been released, so we can only hope that they have plans for a few Android-based devices in the near future. With its release in November 2007, the system itself is still in asoftware-only beta. This is good news for developers because it gives us a rare advance look at a future system and a chance to begin developing applications that will run as soon as the hardware is released.NOTE:This strategy clearly gives the Open Handset Alliance a big advantage over other cell phone operating system developers, because there could be an uncountable number of applications available immediately for the first devices released to run Android.Introduction to AndroidAndroid, as a system, is a Java-based operating system that runs on the Linux 2.6 kernel. The system is very lightweight and full featured. Android applications are developed using Java and can be ported rather easily to the new platform. If you have not yet downloaded Java or are unsure about which version you need, I detail the installation of the development environment in Chapter 2. Other features of Android include an accelerated 3-D graphics engine (based on hardware support), database support powered by SQLite, and an integrated web browser.If you are familiar with Java programming or are an OOP developer of any sort, you are likely used to programmatic user interface (UI) development—that is, UI placement which is handled directly within the program code. Android, while recognizing and allowing for programmatic UI development, also supports the newer, XML-based UI layout. XML UI layout is a fairly new concept to the average desktop developer. I will cover both the XML UI layout and the programmatic UI development in the supporting chapters of this book.One of the more exciting and compelling features of Android is that, because of its architecture, third-party applications—includi ng those that are “home grown”—are executed with the same system priority as those that are bundled with the core system. This is a major departure from most systems, which give embedded system apps a greater execution priority than the thread priority available to apps created by third-party developers. Also, each application is executed within its own thread using a very lightweight virtual machine.Aside from the very generous SDK and the well-formed libraries that are available to us to develop with, the most exciting feature for Android developers is that we now have access to anything the operating system has access to. In other words, if you want to create an application that dials the phone, you have access to the phone’s dialer; if you want to creat e anapplication that utilizes the phone’s internal GPS (if equipped), you have access to it. The potential for developers to create dynamic and intriguing applications is now wide open.On top of all the features that are available from the Android side of the equation, Google has thrown in some very tantalizing features of its own. Developers of Android applications will be able to tie their applications into existing Google offerings such as Google Maps and the omnipresent Google Search. Suppose you want to write an application that pulls up a Google map of where an incoming call is emanating from, or you want to be able to store common search results with your contacts; the doors of possibility have been flung wide open with Android.Chapter 2 begins your journey to Android development. You will learn the how’s and why’s of using specific development environments or integrated development environments (IDE), and you will download and install the Java IDE Eclipse.2 Application: Hello World2.1 Key Skills & Concepts●Creating new Android projects●Working with Views●Using a TextView●Modifying the main.xml file●Running applications on the Android EmulatorIn this chapter, you will be creating your first Android Activity. This chapter examines the application-building process from start to finish. I will show you how to create an Android project in Eclipse, add code to the initial files, and run the finished application in the Android Emulator. The resulting application will be a fully functioning program running in an Android environment.Actually, as you move through this chapter, you will be creating more than one Android Activity. Computer programming tradition dictates that your first application be the typical Hello World! application, so in the first section you will create a standard Hello World!application with just a blank background and the “Hello World!” text. Then, for the sake of enabling you to get to know the language better, the next section explains in detail the files automatically created by Android for your Hello World! application. You will create two iterations of this Activity, each using different techniques for displaying information to the screen. You will also create two different versions of a Hello World! application that will display an image that delivers the “Hello World!” message. This will give you a good introduction to the controls and inner workings of Android.NOTE:You will often see “application” and “Activity” used interchangeably. The difference between the two is that an application can be composed of multiple Activities, but one application must have at least one Activity. Each “window” or screen of your application is a separate Activity. Therefore, if you create a fairly simple application with only one screen of data (like the Hello World! application in this chapter), that will be one Activity. In future chapters you will create applications with multiple Activities.To make sure that you get a good overall look at programming in Android, in Chapter 6 you will create both of these applications in the Android SDK command-line environment for Microsoft Windows and Linux. In other words, this chapter covers the creation process in Eclipse, and Chapter 6 covers the creation process using the command-line tools. Therefore, before continuing, you should check that your Eclipse environment is correctly configured. Review the steps in Chapter 3 for setting the PATH statement for the Android SDK. You should also ensure that the JRE is correctly in your PATH statement.TIP:If you have configuration-related issues while attempting to work with any of the command-line examples, try referring to the configuration steps in Chapters 2 and 3; and look at the Android SDK documentation.2.2 Creating Your First Android Project in EclipseTo start your first Android project, open Eclipse. When you open Eclipse for the first time, it opens to an empty development environment (see Figure 5-1), which is where you want to begin. Your first task is to set up and name the workspace for your application. Choose File | New | Android Project, which will launch the New Android Project wizard.CAUTION Do not select Java Project from the New menu. While Android applications are written in Java, and you are doing all of your development in Java projects, this option will create a standard Java application. Selecting Android Project enables you to create Android-specific applications.If you do not see the option for Android Project, this indicates that the Android plugin for Eclipse was not fully or correctly installed. Review the procedure in Chapter 3 for installing the Android plugin for Eclipse to correct this.2.3 The New Android Project wizard creates two things for youA shell application that ties into the Android SDK, using the android.jar file, and ties the project into the Android Emulator. This allows you to code using all of the Android libraries and packages, and also lets you debug your applications in the proper environment.Your first shell files for the new project. These shell files contain some of the vital application blocks upon which you will be building your programs. In much the same way as creating a Microsoft .NET application in Visual Studio generates some Windows-created program code in your files, using the Android Project wizard in Eclipse generates your initial program files and some Android-created code. In addition, the New Android Project wizard contains a few options, shown next, that you must set to initiate your Android project. For the Project Name field, for purposes of this example, use the title HelloWorldText. This name sufficiently distinguishes this Hello World! project from the others that you will be creating in this chapter.In the Contents area, keep the default selections: the Create New Project in Workspace radio button should be selected and the Use Default Location check box should be checked. This will allow Eclipse to create your project in your default workspace directory. The advantage of keeping the default options is that your projects are kept in a central location, which makes ordering, managing, and finding these projects quite easy. For example, if you are working in a Unix-based environment, this path points to your $HOME directory.If you are working in a Microsoft Windows environment, the workspace path will be C:/Users/<username>/workspace, as shown in the previous illustration. However, for any number of reasons, you may want to uncheck the Use Default Location check box and select a different location for your project. One reason you may want to specify a different location here is simply if you want to choose a location for this specific project that is separate fromother Android projects. For example, you may want to keep the projects that you create in this book in a different location from projects that you create in the future on your own. If so, simply override the Location option to specify your own custom location directory for this project.附件B外文文献(中文)Android:一个程序员的入门书1 什么是Android1.1 主要技巧和思想●历史的嵌入式器件编程●开放手机联盟的解释●第一眼看到Android的主屏幕可以这么说,暂时,传统的桌面应用程序开发者已经被惯坏了。

手机系统安卓系统中英文对照外文翻译文献

手机系统安卓系统中英文对照外文翻译文献

中英文对照外文翻译文献(文档含英文原文和中文翻译)译文:深入理解安卓系统的安全性下一代开放操作系统的主流将不会在桌面上,但是将会出现在我们每天携带的手机上。

这些开放性的环境将会带领这些新的应用可能集成这些已经存在的在线服务,当然随着日以具增的数据与服务在手机上的支持,手机上的安全缺陷也越发明显。

下一代操作系统本质在于是否提供一个完整综合的安全平台。

由开放手机联盟(open Handset Alliance 谷歌领导)所开发的android 系统是一个被广泛看好的一个手机开源系统,该系统提供一个基本的操作系统,一个中间件应用层,一个java开发工具和一个系统应用收集器(collection of systemapplications )。

尽管android SDK自2007年就发布了,但是第一部android 手机却在2008年10月才诞生。

自从这时起谷歌开起了自己的时代,T-Mobile的G1的制造商台湾HTC估算G1的发货量在2008年底已经超过100万部。

据业内人士预期该G1手机的销量将会在2009年继续保持。

不久的将来其他许多手机供应商要计划支持这个系统。

一个围绕android庞大的开发者社区已经建立,同时很多新的产品和应用已经可以在android上使用。

一个Android的主要卖点是它使开发人员无缝把在线服务扩展到手机。

这方面最明显的例子是谷歌的紧密集成Gmail,日历和联系人Web应用程序通过该系统。

用户只需提供一个android用户名和密码,其手机自动同步与谷歌的服务。

其他厂商正在迅速适应自己的现有的即时通讯,社交网络和游戏服务。

Android和许多企业寻找新途径来整合他们的自己已有的业务到android上。

传统的台式机和服务器的操作系统一直在努力进行安全功能的集成。

这些个人和商业应用在单一平台的很出色,然而这一块业务一个手机平台上像android上不是很有用。

它给了许多研究人员希望。

基于Android开发的外文文献

基于Android开发的外文文献

AndroidAndroid, as a system, is a Java-based operating system that runs on the Linux 2、6 kernel、The system is very lightweight and full featured、Android applications are developed using Java and can be ported rather easily to the new platform、If you have not yet downloaded Java or are unsure about which version you need, I detail the installation of the development environment in Chapter 2、Other features of Android include an accelerated 3-D graphics engine (based on hardware support), database support powered by SQLite, and an integrated web browser、If you are familiar with Java programming or are an OOP developer of any sort, you are likely used to programmatic user interface (UI) development—that is, UI placement which is handled directly within the program code、Android, while recognizing and allowing for programmatic UI development, also supports the newer, XML-based UI layout、XML UI layout is a fairly new concept to the average desktop developer、I will cover both the XML UI layout and the programmatic UI development in the supporting chapters of this book、One of the more exciting and compelling features of Android is that, because of its architecture, third-party applications—including those that are “home grown”—are executed with the same system priority as those that are bundled with the core system、This is a major departure from most systems, which give embedded system apps a greater execution priority than the thread priority available to apps created by third-party developers、Also, each application is executed within its own thread using a very lightweight virtual machine、Aside from the very generous SDK and the well-formed libraries that are available to us to develop with, the most exciting feature for Android developers is that we now have access to anything the operating system has access to、In other words, if you want to create an application that dials the phone, you have access to the phone’s dialer; if you want to create an application that utilizes the phone’s internalGPS (if equipped), you have access to it、The potential for developers to create dynamic and intriguing applications is now wide open、On top of all the features that are available from the Android side of the equation, Google has thrown in some very tantalizing features of its own、Developers of Android applications will be able to tie their applications into existing Google offerings such as Google Maps and the omnipresent Google Search、Suppose you want to write an application that pulls up a Google map of where an incoming call is emanating from, or you want to be able to store common search results with your contacts; the doors of possibility have been flung wide open with Android、Chapter 2 begins your journey to Android development、You will learn the how’s and why’s of using specific development environments or integrated development environments (IDE), and you will download and install the Java IDE Eclipse、Application ComponentsA 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 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 doesn't incorporate the code of the other application or link to it、Rather, it simply starts up that piece of the other 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 don't have a single entry point for everything 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:ActivitiesAn activity presents a visual user interface for one focused endeavor the user can undertake、For example, 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, 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、Each activity is given a default window to draw in、Typically, the window fills the screen, but it might be smaller than the screen and float on top of other windows、An activity can also make use of additional windows — for example, a pop-up dialog that calls for a user response in the midst of the activity, or a window that presents users with vital information when they select a particular item on-screen、The visual content of the window is provided by a hierarchy of views — objects derived from the base View class、Each view controls a particular rectangular space within the window、Parent views contain and organize the layout of their children、Leaf views (those at the bottom of the hierarchy) draw in the rectangles they control and respond to user actions directed at that space、Thus, views are where the activity's interaction with the user takes place、For example, a view might display a small image and initiate an action when theuser taps that image、Android has a number of ready-made views that you can use —including buttons, text fields, scroll bars, menu items, check boxes, and more、A view hierarchy is placed within an activity's window by the Activity、setContentView() method、The content view is the View object at the root of the hierarchy、(See the separate User Interface document for more information on views and the hierarchy、)ServicesA service doesn'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、A prime example is a media player playing songs from a play list、The player application would probably have one or more activities that allow the user to choose songs and start playing them、However, the music playback itself would not be handled by an activity because users will expect the music to keep playing even after they leave the player and begin something different、To keep the music going, the media player activity could start a service to run in the background、The system would then keep the music playback service running even after the activity that started it leaves the screen、It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running)、While connected, you can communicate with the service through an interface that the service exposes、For the music service, this interface might allow users to pause, rewind, stop, and restart the playback、Like activities and the other components, services run in the main thread of the application process、So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback)、SeeProcesses and Threads, later、Broadcast receiversA 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 timezone 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'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 message、Content providersA content provider makes a specific set of the application's data available to other applications、The data can be stored in the , 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's involved、See the separate Content Providers document for more information on usingcontent providers、Whenever there'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、Key Skills & Concepts●Creating new Android projects●Working with Views●Using a TextView●Modifying the main、xml fileCreating Your First Android Project in EclipseTo start your first Android project, open Eclipse、When you open Eclipse for the first time, it opens to an empty development environment (see Figure 5-1), which is where you want to begin、Your first task is to set up and name the workspace for your application、Choose File | New | Android Project, which will launch the New Android Project wizard、CAUTION Do not select Java Project from the New menu、While Android applications are written in Java, and you are doing all of your development in Java projects, this option will create a standard Java application、Selecting Android Project enables you to create Android-specific applications、If you do not see the option for Android Project, this indicates that the Android plugin for Eclipse was not fully or correctly installed、Review the procedure in Chapter 3 for installing the Android plugin for Eclipse to correct this、The New Android Project wizard creates two things for youA shell application that ties into the Android SDK, using the android、jar file, andties the project into the Android Emulator、This allows you to code using all of the Android libraries and packages, and also lets you debug your applications in the proper environment、Your first shell files for the new project、These shell files contain some of the vital application blocks upon which you will be building your programs、In much the same way as creating a Microsoft 、NET application in Visual Studio generates some Windows-created program code in your files, using the Android Project wizard in Eclipse generates your initial program files and some Android-created code、In addition, the New Android Project wizard contains a few options, shown next, that you must set to initiate your Android project、For the Project Name field, for purposes of this example, use the title HelloWorldText、This name sufficiently distinguishes this Hello World! project from the others that you will be creating in this chapter、In the Contents area, keep the default selections: the Create New Project in Workspace radio button should be selected and the Use Default Location check box should be checked、This will allow Eclipse to create your project in your default workspace directory、The advantage of keeping the default options is that your projects are kept in a central location, which makes ordering, managing, and finding these projects quite easy、For example, if you are working in a Unix-based environment, this path points to your $HOME directory、If you are working in a Microsoft Windows environment, the workspace path will be C:/Users/<username>/workspace, as shown in the previous illustration、However, for any number of reasons, you may want to uncheck the Use Default Location check box and select a different location for your project、One reason you may want to specify a different location here is simply if you want to choose a location for this specific project that is separate from other Android projects、For example, you may want to keep the projects that you create in this book in a different location from projects that you create in the future on your own、If so, simply override the Location option to specify your own custom location directory for this project、。

android文献中英对照

android文献中英对照

英文原文Application FundamentalsAndroid 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 vehicle for distributing the application and installing it on mobile devices; it's the file users download to their devices. All the code in a single .apk file is considered to be one application.In many ways, each Android application lives in its own world:(1)By default, every application runs in its own Linux process. Android starts the process when any of the application's code needs to be executed, and shuts down the process when it's no longer needed and system resources are required by other applications.(2)Each process has its own virtual machine (VM), so application code runs in isolation from the code of all other applications.(3)By default, each application is assigned a unique Linux user ID. Permissions are set so that the application's files are visible only to that user and only to the application itself — although there are ways to export them to other applications as well.It's possible to arrange for two applications to share the same user ID, in which case they will be able to see each other's files. To conserve system resources, applications with the same ID can also arrange to run in the same Linux process, sharing the same VM.Application ComponentsA 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 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 doesn'tincorporate the code of the other application or link to it. Rather, it simply starts up that piece of the other 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 don't have a single entry point for everything 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:(1)ActivitiesAn activity presents a visual user interface for one focused endeavor the user can undertake. For example, 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, 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.Each activity is given a default window to draw in. Typically, the window fills the screen, but it might be smaller than the screen and float on top of other windows. An activity can also make use of additional windows — for example, a pop-up dialog that calls for a user response in the midst of the activity, or a window that presents users with vital information when they select a particular item on-screen.The visual content of the window is provided by a hierarchy of views — objects derived from the base View class. Each view controls a particular rectangular spacewithin the window. Parent views contain and organize the layout of their children. Leaf views (those at the bottom of the hierarchy) draw in the rectangles they control and respond to user actions directed at that space. Thus, views are where the activity's interaction with the user takes place.For example, a view might display a small image and initiate an action when the user taps that image. Android has a number of ready-made views that you can use —including buttons, text fields, scroll bars, menu items, check boxes, and more.A view hierarchy is placed within an activity's window by the Activity.setContentView() method. The content view is the View object at the root of the hierarchy. (See the separate User Interface document for more information on views and the hierarchy.)(2)ServicesA service doesn'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.A prime example is a media player playing songs from a play list. The player application would probably have one or more activities that allow the user to choose songs and start playing them. However, the music playback itself would not be handled by an activity because users will expect the music to keep playing even after they leave the player and begin something different. To keep the music going, the media player activity could start a service to run in the background. The system would then keep the music playback service running even after the activity that started it leaves the screen.It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running). While connected, you can communicate with the service through an interface that the service exposes. For the music service, this interface might allow users to pause, rewind, stop, and restart the playback.Like activities and the other components, services run in the main thread of theapplication process. So that they won't block other components or the user interface, they often spawn another thread for time-consuming tasks (like music playback). See Processes and Threads, later.(3)Broadcast receiversA 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 timezone 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'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 message.(4)Content providersA content provider makes a specific set of the application'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's involved.See the separate Content Providers document for more information on using content providers.Whenever there'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: intentsContent providers are activated when they're targeted by a request from a ContentResolver. The other three components —activities, services, and broadcast receivers — are activated by asynchronous messages called intents. An intent is an Intent object that holds the content of the message. For activities and services, it names the action being requested and specifies the URI of the data to act on, among other things. For example, it might convey a request for an activity to present an image to the user or let the user edit some text. For broadcast receivers, the Intent object names the action being announced. For example, it might announce to interested parties that the camera button has been pressed.There are separate methods for activating each type of component:(1)An activity is launched (or given something new to do) by passing an Intent object to Context.startActivity() or Activity.startActivityForResult(). The responding activity can look at the initial intent that caused it to be launched by calling its getIntent() method. Android calls the activity's onNewIntent() method to pass it any subsequent intents. One activity often starts the next one. If it expects a result back from the activity it's starting, it calls startActivityForResult() instead of startActivity(). For example, if it starts an activity that lets the user pick a photo, it might expect to be returned the chosen photo. The result is returned in an Intent object that's passed to the calling activity's onActivityResult() method.(2)A service is started (or new instructions are given to an ongoing service) by passing an Intent object to Context.startService(). Android calls the service's onStart() method and passes it the Intent object. Similarly, an intent can be passed to Context.bindService() to establish an ongoing connection between the calling component and a target service. The service receives the Intent object in an onBind() call. (If the service is not already running, bindService() can optionally start it.) Forexample, an activity might establish a connection with the music playback service mentioned earlier so that it can provide the user with the means (a user interface) for controlling the playback. The activity would call bindService() to set up that connection, and then call methods defined by the service to affect the playback.A later section, Remote procedure calls, has more details about binding to a service.(3)An application can initiate a broadcast by passing an Intent object to methods like Context.sendBroadcast(), Context.sendOrderedBroadcast(), and Context.sendStickyBroadcast() in any of their variations.Android delivers the intent to all interested broadcast receivers by calling their onReceive() methods. For more on intent messages, see the separate article, Intents and Intent Filters.Shutting down componentsA content provider is active only while it's responding to a request from a ContentResolver. And a broadcast receiver is active only while it's responding to a broadcast message. So there's no need to explicitly shut down these components.Activities, on the other hand, provide the user interface. They're in a long-running conversation with the user and may remain active, even when idle, as long as the conversation continues. Similarly, services may also remain running for a long time. So Android has methods to shut down activities and services in an orderly way:An activity can be shut down by calling its finish() method. One activity can shut down another activity (one it started with startActivityForResult()) by calling finishActivity().A service can be stopped by calling its stopSelf() method, or by calling Context.stopService().Components might also be shut down by the system when they are no longer being used or when Android must reclaim memory for more active components. A later section, Component Lifecycles, discusses this possibility and its ramifications in more detail.The manifest fileBefore Android can start an application component, it must learn that the component exists. Therefore, applications declare their components in a manifest file that's bundled into the Android package, the .apk file that also holds the application's code, files, and resources.The manifest is a structured XML file and is always named AndroidManifest.xml for all applications. It does a number of things in addition to declaring the application's components, such as naming any libraries the application needs to be linked against (besides the default Android library) and identifying any permissions the application expects to be granted.But the principal task of the manifest is to inform Android about the application's components.Intent filtersAn Intent object can explicitly name a target component. If it does, Android finds that component (based on the declarations in the manifest file) and activates it. But if a target is not explicitly named, Android must locate the best component to respond to the intent. It does so by comparing the Intent object to the intent filters of potential targets. A component's intent filters inform Android of the kinds of intents the component is able to handle. Like other essential information about the component, they're declared in the manifest file.A component can have any number of intent filters, each one declaring a different set of capabilities. If it doesn't have any filters, it can be activated only by intents that explicitly name the component as the target.For a broadcast receiver that's created and registered in code, the intent filter is instantiated directly as an IntentFilter object. All other filters are set up in the manifest.For more on intent filters, see a separate document, Intents and Intent Filters.中文译文应用程序基础Android DevelopersAndroid应用程序使用Java编程语言开发。

安卓应用基础中英文对照外文翻译文献

安卓应用基础中英文对照外文翻译文献

中英文对照外文翻译(文档含英文原文和中文翻译)Android Application FundamentalsAndroid applications are written in the Java programming language. The Android SDK tools compile the code—along with any data and resource files—into an Android package, an archive file with an .apk suffix. All the code in a single .apk file is considered to be one application and is the file that Android-powered devices use to install the application.Once installed on a device, each Android application lives in its own security sandbox:The Android operating system is a multi-user Linux system in which each application is a different user.By default, the system assigns each application a unique Linux user ID (the ID is used only by the system and is unknown to the application). The system sets permissions for all the files in an application so that only the user ID assigned to that application can access them.Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.By default, every application runs in its own Linux process. Android starts the process when any of the application'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 applications. In this way, the Android system implements the principle of least privilege. That is, each application, 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 application cannot access parts of the system for which it is not given permission.However, there are ways for an application to share data with other applications and for an application to access system services:It's possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).An application 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 application permissions must be granted by the user at install time.That covers the basics regarding how an Android application exists within the system. The rest of this document introduces you to:1、The core framework components that define your application.2、The manifest file in which you declare components and required device features for your application.3、Resources that are separate from the application code and allow your application to gracefully optimize its behavior for a variety of device configurations.Application ComponentsApplication components are the essential building blocks of an Android application. Each component is a different point through which the system can enter your application. Not all components are actual entry points for the user and some depend on each other, but each oneexists as its own entity and plays a specific role—each one is a unique building block that helps define your application's overall behavior.There are four different types of application 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 application components:ActivitiesAn activity represents a single screen with a user interface. For example, an email application 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 application, each one is independent of the others. As such, a different application can start any one of these activities (if the email application allows it). For example, a camera application can start the activity in the email application that composes new mail, in order for the user to share a picture.An activity is implemented as a subclass of Activity and you can learn more about it in the Activities developer guide.ServicesA 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 application, 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.A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide.Content providersA content provider manages a shared set of application data. You can store the data in the file system, an SQLite database, on the web, or any other persistent storage location your application can access. Through the content provider, other applications can query or evenmodify 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 application 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 providers are also useful for reading and writing data that is private to your application and not shared. For example, the Note Pad sample application uses a content provider to save notes.A content provider is implemented as a subclass of ContentProvider and must implement a standard set of APIs that enable other applications to perform transactions. For more information, see the Content Providers developer guide.Broadcast receiversA 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. 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. 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.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.A unique aspect of the Android system design is that any application can start another application’s component. For example, if you want the user to capture a photo with the device camera, there's probably another application that does that and your application 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 application. Instead, you can simply start the activity in the camera application that captures a photo. When complete, the photo is even returned to your application so you can use it. To the user, it seems as if the camera is actually a part of your application.When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component. For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application's process. Therefore, unlike applications on most other systems, Android applications don't have a single entry point (there's no main()function, for example).Because the system runs each application in a separate process with file permissions that restrict access to other applications, your application cannot directly activate a component from another application. The Android system, however, can. So, to activate a component in another application, 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.Activating ComponentsThree 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. T he content resolver handles all direct transactions with the content provider so that the component that's performing transactions with the provider doesn't need to and instead calls methods onthe 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 passingan 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 passingan Intent to startService(). Or you can bind to the service by passing an Intent to bindService().You can initiate a broadcast by passing an Intent to methodslike sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().You can perform a query to a content provider by calling query() on a ContentResolver.For more information about using intents, see the Intents and Intent Filters document. More information about activating specific components is also provided in the following documents: Activities, Services, BroadcastReceiver and Content Providers.Declaring componentsThe primary task of the manifest is to inform the system about the application's components. For example, a manifest file can declare an activity as follows:In the <application> element, the android:icon attribute points to resources for an icon that identifies the application.In the <activity> element, the android:name at tribute specifies the fu lly qualified class name of the Activity subclass and the android:label attributes specifies a string to use as the user-visible label for the activity.You must declare all application components this way:1、<activity>elements for activities2、<service> elements for services3、<receiver>elements for broadcast receivers4、<provider>elements for content providersActivities, 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 manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system bycalling registerReceiver().Declaring component capabilitiesAs discussed above, in Activating Components, you can use an Intent to 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 in 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 you’d 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 multiple components that can perform the action described by the intent, then the user selects which one to use.The way the system identifies the components that can respond to an intent is by comparing the intent received to the intent filters provided in the manifest file of other applications on the device.When you declare a component in your application's 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 addingan <intent-filter>element as a child of the component's declaration element.For 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 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 application’s “send” activity and launches it when you invoke the intent with startActivity().For more about creating intent filters, see the Intents and Intent Filters document.Declaring application requirementsThere are a variety of devices powered 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, it's important that you clearly define a profile for the types of devices your application supports by declaring 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.For example, if your application requires a camera and uses APIs introduced in Android 2.1 (API Level7), you should declare these as requirements in your manifest file. That way, devices that do not have a camera and have an Android version lower than 2.1 cannot install your application from Google Play.However, you can also declare that your application uses the camera, but doesnot require it. 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.Here are some of the important device characteristics that you should consider as you design and develop your application:Screen size and densityIn order to categorize devices by their screen type, Android defines two 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 dpi—dots 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.The screen sizes are: small, normal, large, and extra large.The screen densities are: low density, medium density, high density, and extra high density.By default, your application is compatible with all screen sizes and densities, because the Android system makes the appropriate adjustments to your UI layout and image resources. However, you should create specialized layouts for certain screen sizes and provide specialized images for certain densities, using alternative layout resources, and by declaring in your manifest exactly which screen sizes your application supports withthe <supports-screens> element.For more information, see the Supporting Multiple Screens document.Input configurationsMany devices provide a different type of user input mechanism, such as a hardware keyboard, a trackball, or a five-way navigation pad. If your application requires a particular kind of input hardware, then you should declare it in your manifest with the <uses-configuration> element. However, it is rare that an application should require a certain input configuration.Device featuresThere are many hardware and software features that may or may not exist on a given Android-powered device, such as a camera, a light sensor, bluetooth, a certain version of OpenGL, or the fidelity of the touchscreen. You should never assume that a certain feature is available on all Android-powered devices (other than the availability of the standard Android library), so you should declare any features used by your application withthe <uses-feature> element.Platform VersionDifferent Android-powered devices often run different versions of the Android platform, such as Android 1.6 or Android 2.3. Each successive version often includes additional APIs not available in the previous version. In order to indicate which set of APIs are available, each platform version specifies an API Level (for example, Android 1.0 is API Level 1 and Android 2.3 is API Level 9). If you use any APIs that were added to the platform after version 1.0, you should declare the minimum API Level in which those APIs were introduced using the <uses-sdk> element.It's important that you declare all such requirements for your application, because, when you distribute your application on Google Play, the store uses these declarations to filter which applications are available on each device. As such, your application should be available only to devices that meet all your application requirements.For more information about how Google Play filters applications based on these (and other) requirements, see the Filters on Google Play document.Application ResourcesAn Android application is composed of more than just code—it requires resources that are separate from the source code, such as images, audio files, and anything relating to the visual presentation of the application. For example, you should define animations, menus, styles, colors, and the layout of activity user interfaces with XML files. Using application resources makes it easy to update various characteristics of your application without modifying code and—by providing sets of alternative resources—enables you to optimize your application for a variety of device configurations (such as different languages and screen sizes).For every resource that you include in your Android project, the SDK build tools define a unique integer ID, which you can use to reference the resource from your application code or from other resources defined in XML. For example, if your application c ontains an image file named logo.png (saved in the res/drawable/ directory), the SDK tools generate a resource IDnamed R.drawable.logo, which you can use to reference the image and insert it in your user interface.One of the most important aspects of providing resources separate from your source code is the ability for you to provide alternative resources for different device configurations. For example, by defining UI strings in XML, you can translate the strings into other languages and save those strings in separate files. Then, based on a language qualifier that you append to the resource directory's name (such as res/values-fr/ for French string values) and the user's language setting, the Android system applies the appropriate language strings to your UI.Android supports many different qualifiers for your alternative resources. The qualifier is a short string that you include in the name of your resource directories in order to define the device configuration for which those resources should be used. As another example, you should often create different layouts for your activities, depending on the device's screen orientation and size. For example, when the device screen is in portrait orientation (tall), you might want a layout with buttons to be vertical, but when the screen is in landscape orientation (wide), the buttons should be aligned horizontally. To change the layout depending on the orientation, you can define two different layouts and apply the appropriate qualifier to each layout's directory name. Then, the system automatically applies the appropriate layout depending on the current device orientation.For more about the different kinds of resources you can include in your application and how to create alternative resources for various device configurations, see theApplication Resources developer guide.安卓应用基础在Java编程语言编写的Android应用程序的Android的SDK工具编译代码以及与任何数据和到一个Android的包,一个归档文件档案资源的.apk后缀,所有的在一个单一的代码.apk文件被认为是一个应用程序,是Android的文件,供电设备来安装应用程序。

Android外文文献翻译11

Android外文文献翻译11

Android Application Fundamentals nguage pil.th.code—alon.wit.an.dat.an.resourc.files—int.an Androi.package.a.archiv.an .apk suffix.Al.th.cod.i..single .apk.considere.t.b.on. applicatio.an.i.th..t.instal.th.application.Once installed on a device, each Android application lives in its own security sandbox:The Android operating system is a multi-user Linux system in which each application is a different user.e .I.(e.onl.b.th.syste.an.i.unknow.t.th.application). Th.syste.set.permission.fo.al.th.file.i.a.applicatio.s.tha.o e.I.assigne.t.tha.applicatio.ca.acces.them.Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.B.default.ever.applicatio.run.i.it.ow.Linu.process.Androi.st art.th.proces.whe.an.o.th.application'.component.nee.t.b.exe cuted.the.shut.dow.th.proces.whe.it'.n.longe.neede.o.whe.th. syste.mus.recove.memor.fo.othe.applications.I.thi.way.th.Androi.syste.implement.the principl.o.leas.pri vilege.Tha.is.eac.application.b.default.ha.acces.onl.t.th.co mponent.tha.i.require.t.d.it.wor.an.n.more.Thi.create..ver.s ecur.environmen.i.whic.a.applicatio.canno.acces.part.o.th.sy ste.fo.whic.i.i.no.give.permission.However, there are ways for an application to share data with other applications and for an application to access system services:It'.possibl.t.arrang.fo.tw.application.t.shar.th.sam.Lin e.ID.i.whic.cas.the.ar.abl.t.acces.eac.other'.files.T.co e.I.ca.als.ar rang.t.ru.i.th.sam.Linu.proces.an.shar.th.sam.V.(th.applicat ion.mus.als.b.signe.wit.th.sam.certificate).A.applicatio.ca.reques.permissio.t.acces.devic.dat.suc.a.th. user'.contacts.SM.messages.th.mountabl.storag.(S.card).camer a.Bluetooth.an.more.Al.applicatio.permission.mus.b.grante.b. e.a.instal.time.Tha.cover.th.basic.regardin.ho.a.Androi.applicatio.exist .withi.th.system.Th.res.o.thi.documen.introduce.yo.to:1.The core framework components that define your application.2.The manifest which you declare components and required device features for your application.3、Resource.tha.ar.separat.fro.th.applicatio.cod.an.allo.you.ap plicatio.t.gracefull.optimiz.it.behavio.fo..variet.o.devic.c onfigurations.Application Componentsponent.ar.th.essentia.buildin.block.o.a. ponen.i..differen.poin.throug.whic ponent.ar.actua.e e.an.som.depen.o.eac.other.bu.eac.on.exist .a.it.ow.entit.an.play..specifi.role—eac.on.i..uniqu.buildin.bloc.tha.help.defin.you.application' .overal.behavior.ponents.Eac.ty p.serve..distinc.purpos.an.ha..distinc.lifecycl.tha.define.h ponen.i.create.an.destroyed.Here are the four types of application components: ActivitiesAn activity e.interface. Fo.example.a.emai.applicatio.migh.hav.on.activit.tha.show..l pos.a.email.an.anothe.activit.fo.readin.emails.Althoug.th.activitie.wor.togethe.t.for e.experienc.i.th.emai.application.eac.on.i.indep enden.o.th.others.A.such..differen.applicatio.ca.star.an.on. o.thes.activitie.(i.th.emai.applicatio.allow.it).Fo.example. .camer.applicatio.ca.star.th.activit.i.th.emai.applicatio.th e.t.shar..picture.An activity is implemented as a subclass of Activity and you can learn more about it in the Activities developer guide. ServicesA service ponen.tha.run.i.th.backgroun.t.perfor. long-runnin.operation.o.t.perfor.wor.fo.remot.processes..ser e.interface.Fo.example..servic.migh.pla e.i.i..differen.application.o e.interactio ponent.suc.a.a.activity.ca.star.th .servic.an.le.i.ru.o.bin.t.i.i.orde.t.interac.wit.it.A service is implemented as a subclass of Service and you can learn more about it in the Services developer guide. Content providersA conten.provider manage..share.se.o.applicatio.data.Y o.ca.stor.th.dat.i.th..a.SQLit.database.o.th.web.o.an.othe.p ersisten.storag.locatio.you.applicatio.ca.access.Throug.th.conten.provider.othe.application.ca.quer.o.eve.modif.th.dat.( i.th.conten.provide.allow.it).Fo.example.th.Androi.syste.pro er'rmation.A.such.an.applicatio.wit.th.prope.permission.ca.quer.par.o.t h.conten.provide.(suc.as ContactsContract.Data.t.rea.an.wri rmatio.abou..particula.person.efu.fo.readin.an.writin.dat.tha .i.privat.t.you.applicatio.an.no.shared.Fo.example.the Not. Pad e..conten.provide.t.sav.notes..conten.provide.i.implemente.a..subclas.of ContentProvider an.mus.implemen..standar.se.o.API.tha.enabl.othe.applicati rmation.se.the Conten.P roviders develope.guide.Broadcast receiversA broadcas.receiver ponen.tha.respond.t.system-w id.broadcas.announcements.Man.broadcast.originat.fro.th.syst em—fo.example..broadcas.announcin.tha.th.scree.ha.turne.off.th. batter.i.low.o..pictur.wa.captured.Application.ca.als.initia t.broadcasts—fo.example.t.le.othe.application.kno.tha.som.dat.ha.bee.down e.Althoug.broadcas .receiver.don'e.interface.the.may creat..statu.ba.notification e.whe..broadcas.even.occurs.Mor. commonly.though..broadcas.receive.i.jus.." ponent.an.i.intende.t.d..ver.minima.amoun.o.work.Fo.instance .i.migh.initiat..servic.t.perfor.som.wor.base.o.th.event. .broadcas.receive.i.implemente.a..subclas.of BroadcastRecei ver an.eac.broadcas.i.delivere.a.an Intent object.Fo.mor. information.se.th.BroadcastReceiver class..uniqu.aspec.o.th.Androi.syste.desig.i.tha.an.applicatio. ca.star.anothe.application’.component.Fo.example.i.yo.wan.t e.t.captur..phot.wit.th.devic.camera.there'.probabl.anot .it.instea. o.developin.a.activit.t.captur..phot.yourself.Yo.don'.nee.t. incorporat.o.eve.lin.t.th.cod.fro.th.camer.application.Inste ad.yo.ca.simpl.star.th.activit.i.th.camer.applicatio.tha.cap plete.th.phot.i.eve.returne.t.you.applica er.i.seem.a.i.th.camer.i.actuall..p ar.o.you.application.ponent.i.start.th.proces.fo.tha.ap plicatio.(i.it'.no.alread.running.an.instantiate.th.classe.n ponent.Fo.example.i.you.applicatio.start.th.ac tivit.i.th.camer.applicatio.tha.capture..photo.tha.activit.r un.i.th.proces.tha.belong.t.th.camer.application.no.i.you.application'.process.Therefore.unlik.application.o.mos.othe.sy stems.Androi.application.don'.hav..singl.entr.poin.(there'.n o main() function.fo.example).Becaus.th.syste.run.eac.applicatio.i..separat.proces.wit. tha.restric.acces.t.othe.applications.you.applicatio.canno.d ponen.fro.anothe.application.Th.Androi.sy ponen.i.anothe.application .yo.mus.delive..messag.t.th.syste.tha.specifie.your intent ponen.fo.you.Activating Componentsponen.types—activities.services.an.broadcas.receivers—ar.activate.b.a.asynchronou.messag.calle.an intent.Intent.b ponent.t.eac.othe.a.runtim.(yo.ca.thin.o.the ponents).whet ponen.belong.t.you.applicatio.o.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.Fo.activitie.an.services.a.inten.define.th.actio.t.perfor .(fo.example.t."view.o."send.something.an.ma.specif.th.UR.o. th.dat.t.ac.o.(ponen.bein.starte.m igh.nee.t.know).Fo.example.a.inten.migh.conve..reques.fo.a.a ctivit.t.sho.a.imag.o.t.ope..we.page.I.som.cases.yo.ca.star.a.activit.t.receiv..result.i.whic.case.th.activit.als.return .th.resul.i.an Intent (fo.example.yo.ca.issu.a.inten.t.le. e.pic..persona.contac.an.hav.i.returne.t.you—th.retur.inten.include..UR.pointin.t.th.chose.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").ponen.type.conten.provider.i.no.activate.b. intents.Rather.i.i.activate.whe.targete.b..reques.fro.a Con tentResolver.Th.conten.resolve.handle.al.direc.transaction.w ponen.that'.performin.trans action.wit.th.provide.doesn'.nee.t.an.instea.call.method.o.t he ContentResolver ye.o.abstractio.bet rmatio.(f o.security).There are separate methods for activating each type of component:You can start an activity (or give it something new to do) by passingan Intent to startActivity()or startActivityForResult( )(when you want the activity to return a result).Yo.ca.star..servic.(o.giv.ne.instruction.t.a.ongoin.serv ice.b.passin.an Intent to startService().O.yo.ca.bin.t.th .servic.b.passin.an Intent tobindService().You can initiate a broadcast by passing an Intent to methods like sendBroadcast(), sendOrderedBroadcast(),or sendStickyBroadcast().You can perform a query to a content provider bycalling query()on a ContentResolver.in.intents.se.the Intent.an.Inten .Filters ponent.i.als.provide.i.th.followin.documents: Activities, Services, BroadcastReceiver and Conten.Providers.Declaring components<?xm.version="1.0.encoding="utf-8"?><manifes....>..<applicatio.android:icon="@drawable/app_icon.png....> ....<activit.android:name="com.example.project.ExampleActivi ty".........android:label="@string/example_label....>....</activity>.........</application></manifest>In the <application>element, theandroid:icon attribute points to resources for an icon that identifies the application.In the <activity>element, the android:name at tribute specifies the fu lly qualified class name of theActivity subclass and the android:label attributes specifies a string to use as the user-visible label for the activity.You must declare all application components this way:1.<activity> elements for activities2.<service> elements for services3.<receiver> elements for broadcast receivers4.<provider> elements for content providersActivities.services.an.conten.provider.tha.yo.includ.i.yo u.sourc.bu.d.no.declar.i.th.manifes.ar.no.visibl.t.th.syste. and.consequently.ca.neve.run.However.broadcas.receiver.ca.b. eithe.declare.i.th.manifes.o.create.dynamicall.i.cod.(as Br oadcastReceiver objects.an.registere.wit.th.syste.b.callingregisterReceiver().Declaring component capabilitiesA.discusse.above.in .an In tent t.star.activities.services.an.broadcas.receivers.Yo.ca ponen.(ponen.c .i.th.intent.However.th.rea.powe.o.intent.lie.i.th.c oncep.o.inten.actions.Wit.inten.actions.yo.simpl.describ.th. typ.o.actio.yo.wan.t.perfor.(an.optionally.th.dat.upo.whic.y ou’ponen .o.th.devic.tha.ca.perfor.th.actio.an.star.it.I.ther.ar.mult ponent.tha.ca.perfor.th.actio.describe.b.th.intent.th e.The way the system identifies the components that can respond to an intent is by comparing the intent received to the intent filters provided in the manifest other applications on the device.ponen.i.you.application'.manifest.yo.ca .optionall.includ.inten.filter.tha.declar.th.capabilitie.o.t ponen.s.i.ca.respon.t.intent.fro.othe.applications.Yo.c ponen.b.addin.an <intent-f ilter> ponent'.declaratio.element.posin..n e.emai.migh.declar.a.inten.filte.i.it.manifes.entr.t.respon. t."send.intent.(i.orde.t.sen.email).A.activit.i.you.applicat io.ca.the.creat.a.inten.wit.th.“send.actio.(ACTION_SEND).whic.th.syste.matche.t.th.emai.ap plication’.“unche.i.whe.yo.invok.th.inten.with star tActivity().For more about creating intent filters, see the Intents and Intent Filters document.Declaring application requirementsTher.ar..variet.o.device.powere.b.Androi.an.no.al.o.the.p rovid.th.sam.feature.an.capabilities.I.orde.t.preven.you.app c.feature.neede.b.y ou.application.it'.importan.tha.yo.clearl.defin..pr.th.type. o.device.you.applicatio.support.b.declarin.devic.an.softwar. requirement.i.you.manifes.file.Mos.o.thes.declaration.ar.informationa.onl.an.th.syste.doe.no.rea.them.bu.externa.service er. whe.the.searc.fo.application.fro.thei.device.e.API.int roduce.i.Androi.2..(AP.Level 7).yo.shoul.declar.thes.a.requ irement.i.you.manifes.file.Tha.way.device.tha.do not hav.. camer.an.hav.a.Androi.version lower tha.2..canno.instal.yo u.applicatio.fro.Googl.Play.e.th.camera .bu.doe.not require it.I.tha.case.you.applicatio.mus.perfo r..chec.a.runtim.t.determin.i.th.devic.ha..camer.an.disabl.a .th.camer.i.on.i.no.available.Here are some of the important device characteristics that you should consider as you design and develop your application: Screen size and densityI.orde.t.categoriz.device.b.thei.scree.type.Androi.defin e.tw.characteristic.fo.eac.device.scree.siz.(th.physica.dime nsion.o.th.screen.an.scree.densit.(th.physica.densit.o.th.pi xel.o.th.screen.o.dpi—dot.pe.inch).T.simplif.al.th.differen.type.o.scree.configura tions.th.Androi.syste.generalize.the.int.selec.group.tha.mak .the.easie.t.target.The screen sizes are: small, normal, large, and extra large. The screen densities are: low density, medium density, high density, and extra high density.patibl.wit.al.scree.size.a n.densities.becaus.th.Androi.syste.make.th.appropriat.adjust you.an.imag.resources.However.yo.shoul.creat. yout.fo.certai.scree.size.an.provid.specialize. you.resources.an .b.declarin.i.you.manifes.exactl.whic.scree.size.you.applica tio.support.wit.the <supports-screens> element.For more information, see the Supporting Multiple Screens document.Input configurationse.inpu.mechanism.suc.a.. hardwar.keyboard..trackball.o..five-wa.navigatio.pad.I.you.a pplicatio.require..particula.kin.o.inpu.hardware.the.yo.shou l.declar.i.i.you.manifes.wit.the <uses-configuration> elem ent.However.i.i.rar.tha.a.applicatio.shoul.requir..certai.in pu.configuration.Device featuresTher.ar.man.hardwar.an.softwar.feature.tha.ma.o.ma.no.exis.o ..give.Android-powere.device.suc.a..camera..ligh.sensor.blue tooth..certai.versio.o.OpenGL.o.th.fidelit.o.th.touchscreen.Yo.shoul.neve.assum.tha..certai.featur.i.availabl.o.al.Andro id-powere.device.(othe.tha.th.availabilit.o.th.standar.Andro i.library)e.b.you.applicatio .wit.the <uses-feature> element.Platform VersionDifferen.Android-powere.device.ofte.ru.differen.version.o.th .Androi.platform.suc.a.Androi.1..o.Androi.2.3.Eac.successiv. versio.ofte.include.additiona.API.no.availabl.i.th.previou.v ersion.I.orde.t.indicat.whic.se.o.API.ar.available.eac.platf or.versio.specifie.an AP.Level (fo.example.Androi.1..i.AP. Leve..an.Androi.2..i.AP.Leve.9).an.API.tha.wer.adde. t.th.platfor.afte.versio.1.0.yo.shoul.declar.th.minimu.AP.Le in.the <uses-sdk> eleme nt.It'.importan.tha.yo.declar.al.suc.requirement.fo.you.appl ication.because.whe.yo.distribut.you.applicatio.o.Googl.Play e.thes.declaration.t.filte.whic.application.ar.av ailabl.o.eac.device.A.such.you.applicatio.shoul.b.availabl.o nl.t.device.tha.mee.al.you.applicatio.requirements.For more information about how Google Play filters applications based on these (and other) requirements, see the Filters on Google Play document.Application Resourcespose.o.mor.tha.jus.code—i.require.resource.tha.ar.separat.fro.th.sourc.code.suc.a.im ages.audi.files.an.anythin.relatin.t.th.visua.presentatio.o. th.application.Fo.example.yo.shoul.defin.animations.menus.st e.interface.wit.XM.files .Usin.applicatio.resource.make.i.eas.t.updat.variou.characte ristic.o.you.applicatio.withou.modifyin.cod.and—b.providin.set.o.alternativ.resources—enable.yo.t.optimiz.you.applicatio.fo..variet.o.devic.config uration.(nguage.an.scree.sizes).Fo.ever.resourc.tha.yo.includ.i.you.Androi.project.th.SD. .t.referenc.th .resourc.fro.you.applicatio.cod.o.fro.othe.resource.define.i .XML.Fo.example.i.you.applicatio.contain.a.imag. logo.png (save.i.the res/drawable/ directory).th.SD.tool.generat..r d .t.referenc.th. e.interface.On.o.th.mos.importan.aspect.o.providin.resource.separat.f ro.you.sourc.cod.i.th.abilit.fo.yo.t.provid.alternativ.resou rce.fo.differen.devic.configurations.Fo.example.b.definin.U. nguage.an.snguag.qualifie .tha.yo.appen.t.th.resourc.directory'.nam.(suc.as res/value s-fr/ er'.languag.setting.th. nguag.string.t.you.UI.Androi.support.man.different qualifiers fo.you.alternat iv.resources.Th.qualifie.i..shor.strin.tha.yo.includ.i.th.na m.o.you.resourc.directorie.i.orde.t.defin.th.devic.configura ed.A.anothe.example.yo.s yout.fo.you.activities.dependin.o .th.device'.scree.orientatio.an.size.Fo.example.whe.th.devic .scree.i.i.portrai.orientatio.(tall)you.wit. ndscap.orientatio. (wide)yo yout.a yout'.Th you.dependin .o.th.curren.devic.orientation.For more about the different kinds of resources you can include in your application and how to create alternative resources for various device configurations, see theApplication Resources developer guide.安卓应用基础在Java编程语言编写的Android应用程序的Android的SDK工具编译代码以及及任何数据和到一个Android的包, 一个归档文件档案资源的.apk后缀, 所有的在一个单一的代码.apk文件被认为是一个应用程序, 是Android的文件, 供电设备来安装应用程序。

Android文档-开发者指南-第一部分:入门-中英文对照版-word

Android文档-开发者指南-第一部分:入门-中英文对照版-word

一、Introduction(入门)0、Introduction to Android(引进到Android )Android provides a rich application frameworkthat allows you to build innovative apps andgames for mobile devices in a Java languageenvironment. The documents listed in the leftnavigation 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 invokedindividually. For instance, anindividual activity provides a single screen fora user interface, and a service independentlyperforms work in the background.Android 应用程序被构建为能够单独地被调用不同的部件的组合。

安卓应用开发中英文对照外文翻译文献

安卓应用开发中英文对照外文翻译文献

安卓应用开发中英文对照外文翻译文献(文档含英文原文和中文翻译)中英文翻译安卓应用开发基础在Java编程语言编写的Android应用程序的Android的SDK工具编译代码以及与任何数据和到一个Android的包,一个归档文件档案资源的.apk后缀,所有的在一个单一的代码.apk文件被认为是一个应用程序,是Android的文件,供电设备来安装应用程序。

一旦安装在设备上,每个Android应用程序的生命在它自己的安全沙箱:而Android操作系统是一个多用户Linux系统中,每个应用程序是一个不同的用户。

默认情况下,每个应用程序的系统分配一个唯一的Linux用户ID (该ID仅用于由系统是未知的应用程序),系统设置所有的应用程序中的文件权限,以便只有用户ID分配给该应用程序可以访问它们。

每个进程都有它自己的虚拟机(VM),因此应用程序的代码在从其他应用程序隔离运行。

默认情况下,每个应用程序运行在它自己的Linux进程。

Android 的启动过程时,应用程序的任何组件需要被执行,然后关闭该进程时,它不再需要或恢复时,系统必须为其他应用程序的内存。

这样一来,Android系统实现了最小特权原则,也就是说,每个应用程序,默认情况下,只能访问的组件,它需要做的工作,没有更多,这将创建一个非常安全的环境,使应用程序无法访问的,这就是它没有给予许可制度的部分。

但是,有一个应用程序的方法与其他应用程序和应用程序访问系统服务的数据:这有可能为两个应用程序安排共享相同的Linux用户ID,在这种情况下,它们能够相互访问的文件。

为了节约使用相同的用户ID系统资源,应用程序还可以安排运行在相同的Linux进程和共享同一个VM (应用也必须使用相同的证书签名)。

应用程序可以请求访问权限,如用户的联系人,短信,可安装存储(SD卡),摄像头,蓝牙等设备的数据,所有应用程序的权限必须由用户在安装时授予。

这涵盖了基本就如何Android应用程序在系统中存在这个文件的其余部分向您介绍:1、框架的核心组件定义应用程序。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

中英文翻译安卓应用开发基础在Java编程语言编写的Android应用程序的Android的SDK工具编译代码以及与任何数据和到一个Android的包,一个归档文件档案资源的.apk后缀,所有的在一个单一的代码.apk文件被认为是一个应用程序,是Android的文件,供电设备来安装应用程序。

一旦安装在设备上,每个Android应用程序的生命在它自己的安全沙箱:而Android操作系统是一个多用户Linux系统中,每个应用程序是一个不同的用户。

默认情况下,每个应用程序的系统分配一个唯一的Linux用户ID(该ID仅用于由系统是未知的应用程序),系统设置所有的应用程序中的文件权限,以便只有用户ID分配给该应用程序可以访问它们。

每个进程都有它自己的虚拟机(VM),因此应用程序的代码在从其他应用程序隔离运行。

默认情况下,每个应用程序运行在它自己的Linux进程。

Android的启动过程时,应用程序的任何组件需要被执行,然后关闭该进程时,它不再需要或恢复时,系统必须为其他应用程序的内存。

这样一来,Android系统实现了最小特权原则,也就是说,每个应用程序,默认情况下,只能访问的组件,它需要做的工作,没有更多,这将创建一个非常安全的环境,使应用程序无法访问的,这就是它没有给予许可制度的部分。

但是,有一个应用程序的方法与其他应用程序和应用程序访问系统服务的数据:这有可能为两个应用程序安排共享相同的Linux用户ID,在这种情况下,它们能够相互访问的文件。

为了节约使用相同的用户ID系统资源,应用程序还可以安排运行在相同的Linux进程和共享同一个VM(应用也必须使用相同的证书签名)。

应用程序可以请求访问权限,如用户的联系人,短信,可安装存储(SD卡),摄像头,蓝牙等设备的数据,所有应用程序的权限必须由用户在安装时授予。

这涵盖了基本就如何Android应用程序在系统中存在这个文件的其余部分向您介绍:1、框架的核心组件定义应用程序。

2、清单文件中声明组件和应用程序所需的设备功能。

3、资源是从应用程序代码分开,并允许您的应用程序正常优化的设备配置各种其行为。

应用程序组件(Application Components)Android的核心功能之一就是一个应用程序可以使用其它应用程序的元素(如果那个应用程序允许的话)。

比如说,如果你的应用程序需要一个图片卷动列表,而另一个应用程序已经开发了一个合用的而又允许别人使用的话,你可以直接调用那个卷动列表来完成工作,而不用自己再开发一个。

你的应用程序并没有吸纳或链接其它应用程序的代码,它只是在有需求的时候启动了其它应用程序的那个功能部分。

为达到这个目的,系统必须在一个应用程序的一部分被需要时启动这个应用程序,并将那个部分的Java对象实例化。

与在其它系统上的应用程序不同,Android应用程序没有为应用准备一个单独的程序入口(比如说,没有main()方法),而是为系统依照需求实例化提供了基本的组件。

共有四种组件类型:活动(Activities)一个 activity代表用户界面的一个独立屏幕。

例如,一个邮件应用程序应该有一个activity 用于显示新邮件列表,另一个activity 用于撰写一封邮件,还有一个activity 用于读取邮件。

尽管所有activitie 协同工作以构成邮件应用程序的用户体验,但彼此之间相对独立。

应次,不同的应用程序能够从任何一个activity 启动(只要邮件应用程序允许)。

例如,用户需要分享一张照片,一个拍照应用程序能够启动邮件应用程序的activity 。

activity 是一个实现了 Activity 的子类,你可以在 Activities 开发者指导部分了解更多。

服务(Services)service是在后台运行,执行长时间操作或者执行远程操作。

service 不提供用户界面。

例如,当用户在另一个应用程序时,一个service 可在后台播放音乐,或者是从网络上获取数据,而不阻断用户与当前activity 的交互。

其他组件,比如一个activity ,为了与该service 互动,可以启动或者绑定它。

service 是一个实现了 Service 的子类,你可以在 Services 开发者指导部分了解更多。

广播接收器(Broadcast receivers)广播接收器是一个专注于接收广播通知信息,并做出对应处理的组件。

很多广播是源自于系统代码的──比如,通知时区改变、电池电量低、拍摄了一张照片或者用户改变了语言选项。

应用程序也可以进行广播──比如说,通知其它应用程序一些数据下载完成并处于可用状态。

应用程序可以拥有任意数量的广播接收器以对所有它感兴趣的通知信息予以响应。

所有的接收器均继承自BroadcastReceiver基类。

广播接收器没有用户界面。

然而,它们可以启动一个activity来响应它们收到的信息,或者用NotificationManager来通知用户。

通知可以用很多种方式来吸引用户的注意力──闪动背灯、震动、播放声音等等。

一般来说是在状态栏上放一个持久的图标,用户可以打开它并获取消息。

内容提供者(Content providers)内容提供者将一些特定的应用程序数据供给其它应用程序使用。

数据可以存储于文件系统、SQLite数据库或其它方式。

内容提供者继承于ContentProvider 基类,为其它应用程序取用和存储它管理的数据实现了一套标准方法。

然而,应用程序并不直接调用这些方法,而是使用一个ContentResolver 对象,调用它的方法作为替代。

ContentResolver可以与任意内容提供者进行会话,与其合作来对所有相关交互通讯进行管理。

参阅独立的内容提供者Content Providers 章节获得更多关于使用内容提供者的内容。

每当出现一个需要被特定组件处理的请求时,Android会确保那个组件的应用程序进程处于运行状态,或在必要的时候启动它。

并确保那个相应组件的实例的存在,必要时会创建那个实例。

Android系统设计的一个独特方面是任何的一个程序都可以启动另一程序的组件。

比如,你想让你的程序可以使用照相机拍照,如果已经有了实现这种功能的程序并且你你的程序能使用它(有权限),那么你就没有再要再写一个新的Activity来实现这个功能。

你的程序不需要包含或者链接这个拍照程序。

相反,你只需要在你的程序中打开这个拍照程序中的实现拍照功能的Activity。

当拍完之后,拍好的照片甚至会自动返回给你的程序。

者对于用户来说,就好像是想拍照功能的程序就是你的这个程序的一部分一样。

当系统启动一个组件之后,如果这个组件所在的程序之前没有运行的话,系统会自动开始这个程序的进程,并初始化这个组件所需要的相关类。

比如,你的程序开启了一个拍照功能程序的Activity,这时系统会启动这个Activity所在的程序,所以这个Activity运行在拍照功能的程序当中,而不是在你的程序中。

所以,不像其他操作系统的中的程序一样,Android程序没有一个单独的入口点(比如没有我们常见的main()函数)。

因为系统中的程序运行在自己的独立进程中,并且程序中的文件都有自己的限制其他程序访问的权限,所以,你的程序不能直接激活其他程序中的组件。

但是Android系统就可以。

具体是这样的实现的,为了激活(activate)其他程序中的组件,你必须向系统发送一个消息来详细说明你要启动其他组件的意图,这样系统才会为你激活这个组件。

激活组件(Activating Components)四大组件中的三个组件——activities、services和broadcast receiver——是由一种叫intent的异步消息来激活的。

这些intents在运行时(runtime)将这些属于你的程序或不同程序的单独的组件绑定在一起(bind),你可以把这些intents看作是需要其他组件的action的messengers。

一个intent就是一个Intent对象,这个intent定义了一种可以激活(activate)某个特定组件或者某种特定类型的组件,这两种情况分别对应两种intent的定义方式或者显示的或者隐式的。

对于activities和services,一个intent定义了要执行的操作(action)(比如,要“view”或者“send”什么)和要操作的数据的URI。

比如,一个intent可能会为一个activity传递一个请求来展示一张图片或者打开一个网页。

有时,你可以启动一个activity来得到返回的结果,在这个例子中这个activity的返回的结果也是一个Intent(比如,你可以发送一个intent让用户选择一个personal contact并返回给你——这个返回的intent就包含了一个指向用户选择的联系人的URI)。

(关于activity和service的启动方式,下面将介绍。

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

最后一种组件类型content provider并不是由intent来激活的(activate)。

而是由接收到ContentResolver的请求时激活的。

它们都各自有自己的方法来激活相应的组件:你可以通过传递一个Intent给startActivity()或startActivityForResult()启动一个activity(或者给他一些新的要做的内容)。

使用startActivityForResult()你将得到一个返回结果。

你可以通过传递一个Intent给startService()来start一个service(或者给一个正在运行的service一些新的指令(instructions))。

或者你可以通过把一个Intent 传递给bindService()来绑定一个service。

你可以通过传递一个Intent给诸如sendBroadcast()、sendOrderedBroadcast()或者sendStickyBroadcast()等方法来初始化一个广播。

你可以通过调用ContentResolver的query()方法来执行一次content provider 的查询操作。

更多的关于intent的内容,可以参看文档中的Intents and Intent Filters。

更多的关于激活特定组件的内容可以参看文档中的:Activities、Services、BroadcastReceiver、Content Providers。

关于Manifest文件在Android系统可以启动一个应用程序组件之前,Android系统必须通过读取这个程序的AndroidManifest.xml(即manifest文件)文件来确定要启动的组件存在。

相关文档
最新文档