版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、<p> lder named src. This is the source code folder for the given sample application. You can use this to view, edit, and recompile the code for any of the applications. Take advantage of this source code to learn
2、 some tricks and tips about the Android platform.</p><p> Android Tools</p><p> The Android SDK supplies developers with a number of powerful and useful tools. Throughout this book, you will u
3、se only a handful of them directly. This section takes a quick look at just a few of these tools, which will be covered in much more depth in the following chapters, as you dive into command-line development.</p>
4、<p><b> NOTE</b></p><p> For more detailed information about the other tools included in the Android SDK, consult the Android doc files.</p><p> emulator.exe</p><p
5、> Arguably one of the most important tools included in the Android SDK is emulator.exe. emulator.exe launches the Android Emulator. The Android Emulator is used toyou're your applications in a pseudo-Android envi
6、ronment. Given that, as of the writing of this book, there were no hardware devices yet released for the Android platform, emulator.exe is going to be your only means to test applications on a “native” platform.</p>
7、;<p> You can run emulator.exe from the command line or execute it from within Eclipse. In this book, you’ll usually let Eclipse launch the Android Emulator environment for you. However, in the interest of giving
8、 you all the information you need to program with the Android SDK outside of Eclipse, Chapter 6 covers command-line usage of emulator.exe when you create your Hello World! applications.</p><p> When using t
9、he Android Emulator to test your applications, you have two choices for navigating the user interface. First, the emulator comes with usable buttons, as shown in Figure 4-1. You can use these buttons to navigate Android
10、and any applications that you develop for the platform.</p><p><b> TIP</b></p><p> The Power On/Off, Volume Up, and Volume Down buttons are slightly hidden to the sides of the virt
11、ual device. They identify themselves when you hover the mouse pointer over them. Given that many higher-end phones now include a touch screen, the second input choice you have when using the emulator is a simulated touch
12、 screen. You use your mouse as a stylus. The objects on the emulator’s screen can be interacted with using the mouse.</p><p><b> adb.exe</b></p><p> Another tool that will become v
13、ery useful to you when you are using command-line programming is Android Debug Bridge or adb (adb.exe). This tool allows you to issue commands to the Emulator.exe tool. When you are working in a command-line environment,
14、 the adb tool allows you to do the following:</p><p> ● Start and stop the server</p><p> ● Install and uninstall applications</p><p> ● Move files to and from the emulator</p
15、><p> MKSDCARD.exe</p><p> MKSDCARD.exe is a very useful tool if you are testing an application that will need to read or write files to or from an SD Memory Card inserted into the mobile device.
16、 MKSDCARD.exe creates a small partition drive on your drive that will hold and retain the test files. The emulator will treat this partition like an SD Memory Card.</p><p><b> DX.exe</b></p&g
17、t;<p> DX.exe is the compiler of the Android SDK. When run against your Java files, DX.exe will create files with .dex extensions—Dalvik executable format. These files are in the correct format to be understood b
18、y, and run on, an Android device.</p><p><b> NOTE</b></p><p> Android executable files are called Dalvik executable files as a reference to the Dalvik virtual machine that Android
19、used to run all applications. The Dalvik virtual machine runs each application in its own thread with the same priority as core Android applications.</p><p> activityCreator(.bat or .pn)</p><p>
20、; activityCreator is a simple command-line tool that is used to set up a basic development environment. When run from the command line, activityCreator will set up the shell files needed to create a basic Android applic
21、ation. Having these shell files is especially useful if you are not using Eclipse. The Android plugin for Eclipse sets up these shell files for you by calling the activityCreator when you create a new project. Depending
22、on what type of environment you are running, you will see the a</p><p><b> APIs</b></p><p> The API, or application programming interface, is the core of the Android SDK. An API is
23、 a collection of functions, methods, properties, classes, and libraries that is used by application developers to create programs that work on specific platforms. The Android API contains all the specific information tha
24、t you need to create applications that can work on and interact with an Android-based application.</p><p> The Android SDK also contains two supplementary sets of APIs—the Google APIs and the Optional APIs.
25、 Subsequent chapters will focus much more on these APIs as you begin writing applications that utilize them. For now, take a quick look at what they include so that you are familiar with their uses.</p><p>
26、 Google API s</p><p> The Google APIs are included in the Android SDK and contain the programming references that allow you to tie your applications into existing Google services. If you are writing an Andr
27、oid application and want to allow your user to access Google services through your application, you need to include the Google API.</p><p> Located in the android.jar file, the Google API is contained withi
28、n the com.google.* package. There are quite a few packages that are included with the Google API. Some of the packages that are shipped in the Google API include those for graphics, portability, contacts, and calendar ut
29、ilities. However, the packages devoted to Google Maps will be the primary focus in this book.</p><p> Using the com.google.android.maps package, which contains information for Google Maps, you can create ap
30、plications that interact seamlessly with the already familiar interface of Google Maps. This one set of packages opens a whole world of useful applications just waiting to be created.</p><p> The Google API
31、 also contains a useful set of packages that allows you to take advantage of the newer Extensible Messaging and Presence Protocol (XMPP) developed by the Jabber open source community. Using XMPP, applications can quickly
32、 become aware of other clients’ presence and availability for the purpose of messaging and communications. The API packages dealing with XMPP are very useful if you want to create a “chat”-style program that utilizes the
33、 phone messaging capabilities.</p><p> Optional APIs</p><p> The Android SDK includes a number of Optional APIs that cover functionality not covered by the standard Android APIs. These Optiona
34、l APIs are considered optional because they deal with functionality that may or may not be present on a given handset device. That is, some devices created for the Android platform may include upgrades and features that
35、others do not; the Optional APIs cover your programming options when trying to utilize these features in your Android applications.</p><p> One of these optional features (which you will use later in the bo
36、ok) is a cell-phone-based GPS. The Android LBS (Location-Based Services) API deals with the functionality needed to receive and utilize information from a device’s GPS unit. (Combine the information in the Android LBS AP
37、I with that in the Google Maps API, and you might have a very useful application that can automatically display a map of where you are located at any given point in time.)</p><p> Other Optional APIs includ
38、e those for utilizing Bluetooth, Wi-Fi, playing MP3s, and accessing 3-D—OpenGL-enable hardware.</p><p> Application Life Cycle</p><p> If you have a decent amount of experience as an applicati
39、on developer, you are familiar with the concept of an application life cycle. An application life cycle consists of the steps that the application’s processes must follow from execution to termination. Every application,
40、 regardless of the language it was written in, has a specific life cycle, and Android applications are no exception. This section examines the life cycle of an ASP application and compares that to an Android application’
41、s l</p><p> Standard ASP Application Life Cycle</p><p> The life cycle of a standard ASP application is similar enough to that of an Android application to make this a good comparison. ASP app
42、lications step through five distinct processes from launch to disposal. These steps are required to be implemented by all ASP applications, and really define what an ASP application is. The steps, in order, are</p>
43、<p> 1. Application_Start</p><p><b> 2. Event</b></p><p> 3. HTTPApplication.Init</p><p> 4. Disposal</p><p> 5. Application_End</p><
44、p> Chapter 4: Exploring the Android SDK 49</p><p> 50 Android: A Programmer’s Guide</p><p><b> TIP</b></p><p> Some ASP reference materials consider Disposal and
45、Application_End to be one step in the life cycle. However, the Disposal call can be intercepted before it is passed to Application_End. This can allow the application to perform specific functions before</p><p
46、> it is actually destroyed.</p><p> Application_Start is called when the application is requested from the server. This process in turn leads into the Event process(es). When all associated application
47、modules have loaded, HTTPApplication.Init is called. The application executes its events, and when the user attempts to close it, Dispose is called. Dispose then passes processing on to the Application_End process, which
48、 closes the application. </p><p> This is a fairly standard application life cycle. Most applications follow similar life cycles: an application is created, loaded, has events, and is destroyed. The followi
49、ng section demonstrates how this compares to the Android application life cycle.</p><p> Android Application Life Cycle</p><p> The Android application life cycle is unique in that the system
50、controls much of the life cycle of the application. All Android applications, or Activities, are run within their own process. All of the running processes are watched by Android and, depending on how the activity is run
51、ning (this is, a foreground activity, background activity, and so forth), Android may choose to end the activity to reclaim needed resources.</p><p><b> NOTE</b></p><p> When decid
52、ing whether an activity should be shut down, Android takes into account several factors, such as user input, memory usage, and processing time.</p><p> Some of the specific methods called during the life cy
53、cle of an android activity are</p><p> ● onCreate</p><p><b> ● onStart</b></p><p> ● Process-specific events (for example: launching activities or accessing a databas
54、e)</p><p><b> ● onStop</b></p><p> ● onDestroy</p><p> Following the same logic as other application life cycles, an Android application is created, the processes are
55、 started, events are fired, processes are stopped, and the application is destroyed. Though there are a few differences, many application developers should be comfortable with the steps in the life cycle.</p><
56、p> 文獻(xiàn)出處:DiMarzio,J.F.Android: A Programmer's Guide[M].McGraw-Hill Prof Med/Tech, 2008:41-50</p><p> NotePad寫字板</p><p> NotePad,允許你打開,創(chuàng)建并且編輯小的筆記。寫字板不是一個全功能的字符</p><p> 編輯器,
57、所以不要期待是和WindowsMobile中word的競爭對手。但是,作為一個演示工具,使用非常少的代碼就能實現(xiàn)這個效果已經(jīng)非常的棒了。</p><p> SkeletonApp框架應(yīng)用</p><p> SkeletonApp,這是一個基本的程序展示了幾個不同的應(yīng)用程序的功能。如字體,按鈕,圖形和表格。如果你想自己運行SkeletonApp,真的不應(yīng)當(dāng)把它排除在外,參考Skelete
58、App,它會提供不少關(guān)于如何執(zhí)行特定的條款。</p><p><b> Snake蛇</b></p><p> 最后一個在AndroidSDK的示例就是這個蛇了。這是一個小的SNAFU風(fēng)格游戲,比月球登陸復(fù)雜。</p><p><b> 注意:</b></p><p> 如果你打開每一個示例
59、應(yīng)用程序的文件夾,你會看到一個文件夾命名為src。這個是給出示例源代碼的文件夾。你可以為其他任何的應(yīng)用程序來查看,編輯并且重新編譯這些代碼。利用這些源代碼來學(xué)一些Android平臺技巧和提示。</p><p> AndroidSDK提供給開發(fā)者一系列功能強(qiáng)大并且有用的工具。在本書內(nèi),你會直接使用它們。本部分對其中的一些工具做一個快速的查看,而在后續(xù)的章節(jié)中會更加深入的進(jìn)行,那就是在命令行開發(fā)中。</p&g
60、t;<p><b> 注意:</b></p><p> 對于AndroidSDK中包含的更多的工具,請查看Android文檔。</p><p> emulator.exe</p><p> AndroidSDk中一個最重要的工具就是這個emulator.exe。emulator.exe啟動Android模擬器。Androi
61、d模擬器被用來在一個假的Android環(huán)境中運行你的應(yīng)用程序。在本書寫作時,還沒有發(fā)布Android平臺可用的硬件,emulator.exe將會是唯一的方法作為測試應(yīng)用程序的平臺。</p><p> 你可以從Eclipse或者命令行中來運行emulator.exe。在本書中,通常會使用Eclipse啟動Android模擬器環(huán)境??傊?,為了給你所有信息關(guān)于在Eclipse之外用AndroidSDK編程。在第六章里
62、會介紹emulator.exe的命令行使用來創(chuàng)建HelloWorld應(yīng)用程序。當(dāng)使用Android模擬器來測試你的應(yīng)用程序,有兩個選擇可以導(dǎo)航到用戶界面。第一,帶按鈕的模擬器,如圖4-1。你可以使用這些導(dǎo)航按鈕來導(dǎo)航Android和任何的你為這個平臺開發(fā)的應(yīng)用程序。</p><p><b> 提示:</b></p><p> 電源On/Off,聲音的大小按鈕被隱藏
63、在虛擬設(shè)備的旁邊。當(dāng)你用鼠標(biāo)移過它們時,會被自動識別。很多的高端手機(jī)現(xiàn)在都包含了觸摸屏,第二個輸入選項就是這個模擬的觸摸屏。使用你的鼠標(biāo)作為一個尖筆。模擬器屏幕上的對象可以相應(yīng)鼠標(biāo)的動作。</p><p><b> adb.exe</b></p><p> 當(dāng)你使用命令行編輯器時另外一個工具會變得非常的有用,它就是Android調(diào)試橋,或者adb.exe。這個工具
64、允許你發(fā)出命令到模擬器工具。當(dāng)你在命令行環(huán)境下工作時,這個adb工具允許你做下列工作。</p><p><b> ●開始并且停止服務(wù)</b></p><p> ●安裝和卸載應(yīng)用程序</p><p> ●移動文件至模擬器或者從那里移動</p><p> MKSDCARD.exe</p><p&g
65、t; MKSDCARD.exe是一個非常有用的工具,當(dāng)你測試一個應(yīng)用程序,而這個程序需要讀取或者寫入文件到一個插入到移動設(shè)備的SD儲存卡中。MKSDCARD.exe在你的驅(qū)動器中創(chuàng)建一個小的驅(qū)動并且會保留測試文件。然后模擬器會把這個小的部分當(dāng)成一個SD儲存卡。</p><p><b> DX.exe</b></p><p> DX.exe是AndroidSDK的
66、編譯器。當(dāng)運行你的Java文件,DX.exe將創(chuàng)建一個</p><p> 帶有.dex后綴—Dalvik可執(zhí)行格式的文件。這些會被Android設(shè)備正確的理解</p><p><b> 和運行。</b></p><p><b> 注意:</b></p><p> Android可執(zhí)行文件是叫
67、做Dalvik可執(zhí)行文件,Dalvik虛擬機(jī)器以自己脈絡(luò)來運行每一個應(yīng)用程序,而且程序的優(yōu)先權(quán)和Android核心程序一致。</p><p> activityCreator(.bat或者.pn)</p><p> activityCreator是一個簡單的命令行工具被用來設(shè)定基本的開發(fā)環(huán)境。當(dāng)從命令行運行時,activityCreator將設(shè)置一個需要的基本Android應(yīng)用程序所需
68、的殼文件。有了這些殼文件是非常有用的,特別是你不使用Eclipse。當(dāng)你創(chuàng)建一個新項目時,AndroidpluginforEclipse通過呼叫activityCreator來設(shè)置這些殼文件。依據(jù)你運行的是哪一種環(huán)境類型,你會看到不 同的activityCreator的腳本文件。如果你使用Windows環(huán)境,這個就會是.bat文件 ,否則就是python(.pn)腳本。簡單的執(zhí)行這些腳本,就會依次的使用正確的參數(shù)來呼叫真正的activi
69、tyCreator過程。</p><p> APIs或者叫做應(yīng)用程序編程接口,是AndroidSDK的核心。一個API是應(yīng)用程序開發(fā)者在特定平臺上創(chuàng)建程序的功能,方法,屬性,類別和庫的集合。AndroidAPI包含所有你創(chuàng)建與Android為基礎(chǔ)程序交互的特定信息。AndroidSDk同樣包含2套api,—谷歌的API和可選的API.后續(xù)的章節(jié)中將重點放在這些API上,因為你將利用它們寫程序。現(xiàn)在,讓我們快速的
70、說明一下它們包含哪些你熟悉的使用。</p><p><b> 谷歌api</b></p><p> 谷歌API含在AndroidSDK中并且包含編程參考允許你綁定你的程序到現(xiàn)有的谷歌服務(wù)中。假如你寫一個應(yīng)用程序允許你的用戶通過你的程序進(jìn)入到谷歌提供的服務(wù)中,你需要包含谷歌的API.找到android.jar文件,谷歌的API包含在com.google.*包裝中。只
71、有很少的包含了谷歌的API.一些包裝隨著API一起發(fā)布包含了圖形,移動性,聯(lián)系人和日歷等工具??傊?,我們會把本書中把重點放在谷歌地圖上。使用com.google.android.maps包裝,這個包含了谷歌的地圖,你可以創(chuàng)建一個應(yīng)用程序無縫的和熟悉的谷歌地圖界面對接。這個包裝打開了一個等待著被開發(fā)的整個有用的應(yīng)用程序世界。</p><p> 谷歌api還包含了一套有用的包裝,來允許你利用由Jabber開放源碼社
72、區(qū)開發(fā)的最新的ExtensibleMessaging和PresenceProtocl(XMPP)。使用XMPP,應(yīng)用程序可以快速知道戶主在場或者是否可用(從信息和通信中)。如果你要利用電話的短信功能來創(chuàng)建一個聊天類的程序,這個處理XMPP的API是非常有用的。</p><p><b> 可選的api</b></p><p> AndroidSDK包含了一些可選的a
73、pi,它包括了一些標(biāo)準(zhǔn)Androidapi未包含的內(nèi)容。說它們是可選的api意味著這些功能在手持設(shè)備上可能出現(xiàn)也可能不出現(xiàn)。也就是說一些為Android平臺創(chuàng)建的設(shè)備可能包含升級或者一些特性而其他的沒有。當(dāng)利用在你的應(yīng)用程序中利用這些可選的API時,包含了你的編程選項。</p><p> 其中的一個可選特性(本書的后面會使用)就叫做電話基礎(chǔ)的GPS.AndroidLBS(位置基礎(chǔ)的服務(wù))api需要接受并利用設(shè)備
74、上GPS單元的信息。如果結(jié)合AndroidLBSapi和谷歌地圖api,你或許有一個非常有用的應(yīng)用程序會實時的顯示你的位置。其它可選的api包含利用藍(lán)牙,Wi-Fi,播放MP3,進(jìn)入并激活3-D-OpenGL硬件等。</p><p> 如果你有相當(dāng)好的編程經(jīng)驗的話,你對應(yīng)用程序的生命周期這一概念應(yīng)該熟悉。一個應(yīng)用程序的生命周期,由一些應(yīng)用程序由開始執(zhí)行到終止的步驟組成。每一個應(yīng)用程序,不是哪一種語言所寫,都有一
75、定的生命周期。Android應(yīng)用程序也沒有例外。本部分會仔細(xì)對比ASP應(yīng)用程序和Android的應(yīng)用程序的生命周期。</p><p> 標(biāo)準(zhǔn)ASP程序應(yīng)用程序生命周期</p><p> 標(biāo)準(zhǔn)ASP應(yīng)用程序的生命周期和一個Android的程序生命周期非常的類似。ASP應(yīng)用程序從開始到結(jié)束有5個步驟。這些步驟對所有的ASP程序是一致的。并且界定了ASP程序是什么。這些步驟按照次序如下:&l
76、t;/p><p> 1.Application_Start(程序開始)</p><p> 2.Event(事件)</p><p> 3.HTTPApplication.Init</p><p> 4.Disposal</p><p> 5.Application_End</p><p>&
77、lt;b> 提示:</b></p><p> 有些ASP的參考材料考慮Disposal和Application_End在生命周期中成為一個步驟。但是,Disposal呼叫可以到達(dá)Application_End之前被打斷。這個可以允許程序在真正結(jié)束之前執(zhí)行特定的功能。</p><p> 當(dāng)應(yīng)用程序被從服務(wù)器要求執(zhí)行,開始呼叫Application_Start。這個過程
78、依次的通向過 程處理。當(dāng)所有相關(guān)的應(yīng)用程序模塊被裝載,HTTPApplicaation.Init被呼叫。程序執(zhí)行事件,并且當(dāng)用戶試圖去關(guān)閉它,Dispose被呼叫。Dispose然后轉(zhuǎn)移過程到Application_End過程,來關(guān)閉程序。這是一個相當(dāng)標(biāo)準(zhǔn)的應(yīng)用程序生命周期。大多數(shù)的程序是這個生命周期:一</p><p> 個應(yīng)用程序被創(chuàng)建,裝載,擁有事件,并且被關(guān)閉。下面說明和Android應(yīng)用程序生命周期的
79、對比。</p><p> Android應(yīng)用程序生命周期是唯一一個系統(tǒng)控制多的應(yīng)用程序生命周期。所有的Android應(yīng)用程序,或者Actiities都運行在自有的過程中。所用的運行過程都被Android觀察,并且取決于活動是如何運行的(就是說,一個前臺活動,一個后臺活動)Android可能選擇去結(jié)束一個消耗系統(tǒng)資源的活動。</p><p><b> 注意:</b>
80、</p><p> 當(dāng)決定是否關(guān)閉一個活動時,Android會考慮一些因素,如用戶輸入,內(nèi)存使用和過程時間。一個Android或者的生命周期以一些特定的方式被稱呼:</p><p><b> ●onCreate</b></p><p><b> ●onStart</b></p><p> ●
81、Process-specific events (for example: launching activities or</p><p> accessingadatabase)</p><p><b> ●onStop</b></p><p> ●onDestroy</p><p> 與其它程序的邏輯一樣,一
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 眾賞文庫僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 安卓開發(fā)外文翻譯--安卓應(yīng)用基礎(chǔ)
- [雙語翻譯]安卓外文翻譯--安卓操作系統(tǒng)的防盜云應(yīng)用
- 外文翻譯---安卓系統(tǒng)的基本描述
- [雙語翻譯]安卓外文翻譯--安卓操作系統(tǒng)的防盜云應(yīng)用(英文)
- 2014年安卓外文翻譯--安卓操作系統(tǒng)的防盜云應(yīng)用
- [雙語翻譯]安卓外文翻譯--安卓操作系統(tǒng)的防盜云應(yīng)用中英全
- 安卓系統(tǒng)的安全性外文翻譯
- 2014年安卓外文翻譯--安卓操作系統(tǒng)的防盜云應(yīng)用.DOCX
- 2014年安卓外文翻譯--安卓操作系統(tǒng)的防盜云應(yīng)用(英文).PDF
- 安卓應(yīng)用基礎(chǔ)畢業(yè)論文外文翻譯
- 安卓 英文 外文 文獻(xiàn)翻譯 android api級別
- [雙語翻譯]--安卓外文翻譯--android與ios安全之戰(zhàn)
- android點菜軟件外文翻譯--基于安卓系統(tǒng)的電子菜單軟件
- 手機(jī)系統(tǒng)外文翻譯---深入理解安卓系統(tǒng)的安全性
- 手機(jī)系統(tǒng)外文翻譯---深入理解安卓系統(tǒng)的安全性
- 手機(jī)系統(tǒng)外文翻譯---深入理解安卓系統(tǒng)的安全性
- android外文翻譯--外文翻譯--在安卓平臺的擊鍵動力學(xué)
- android外文翻譯--外文翻譯--在安卓平臺的擊鍵動力學(xué)
- android點菜軟件外文翻譯--基于安卓系統(tǒng)的電子菜單軟件
- android外文翻譯--深入理解安卓系統(tǒng)的安全性
評論
0/150
提交評論