




下載本文檔
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、AndroidAndroid, as a system, is a Java-based operating system that runs on the Linux2.6 kernel. The system is very lightweight and full featured. Android applications aredeveloped using Java and can be ported rather easily to the new platform. If youhave not yet downloaded Java or are unsure about w
2、hich version you need, I detailthe installation of the development environment in Chapter 2. Other features ofAndroid 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
3、are an OOP developer of any sort,you are likely used to programmatic user interface (UI) developmentthat is, UIplacement which is handled directly within the program code. Android, whilerecognizing and allowing for programmatic UI development, also supports thenewer, XML-based UI layout. XML UI layo
4、ut is a fairly new concept to the averagedesktop developer. I will cover both the XML UI layout and the programmatic UIdevelopment in the supporting chapters of this book.Oneof the more exciting and compelling features of Android is that, because ofits architecture, third-party applicationsincluding
5、 thosethat are“home grown”are executed with the same system priority as thosethat 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 threadpriority available to apps created by third-party developers. Al
6、so, each application isexecuted within its ownthread using a very lightweight virtual machine.Aside from the very generous SDK and the well-formed libraries that areavailable to us to develop with, the most exciting feature for Androiddevelopers is that we now have access to anything the operating s
7、ystem has accessto. In other words, if you want to create an application that dials the phone, you haveaccess to the phones dialer; if you want tocreate an application that utilizes the phones internal GPS (if equipped), you haveaccess to it. The potential for developers to create dynamic and intrig
8、uingapplications is now wide open.On top of all the features that are available from the Android side of theequation, Google has thrown in some very tantalizing features of its own.Developers of Android applications will be able to tie their applications into existingGoogle offerings such as Google
9、Maps and the omnipresent Google Search.Suppose you want to write an application that pulls up a Google mapof where anincoming call is emanating from, or you want to be able to store common searchresults with your contacts; the doors of possibility have been flung wide open withAndroid.Chapter 2 begi
10、ns your journey to Android development. You will learn the hows and whys o f using specific development environments or integrateddevelopment environments (IDE), and you will download and install the Java IDEEclipse.Application ComponentsA central feature of Android is that one application can make
11、use of elements ofother applications (provided those applications permit it). For example, if yourapplication needs to display a scrolling list of images and another application hasdeveloped a suitable scroller and made it available to others, you can call upon thatscroller to do the work, rather th
12、an develop your own. Your application doesntincorporate the code of the other application or link to it. Rather, it simply starts upthat piece of the other application when the need arises.For this to work, the system must be able to start an application process whenany part of it is needed, and ins
13、tantiate the Java objects for that part. Therefore,unlike applications on most other systems, Android applications dont have a singleentry point for everything in the application (no main() function, for example). Rather,they have essential components that the system can instantiate and run as neede
14、d.There are four types of components:ActivitiesAn activity presents a visual user interface for one focused endeavor the usercan undertake. For example, an activity might present a list of menu items users canchoose from or it might display photographs along with their captions. A textmessaging appl
15、ication might have one activity that shows a list of contacts to sendmessages to, a second activity to write the message to the chosen contact, and otheractivities to review old messages or change settings. Though they work together toform a cohesive user interface, each activity is independent of t
16、he others. Each one isimplemented as a subclass of the Activity base class.An application might consist of just one activity or, like the text messagingapplication just mentioned, it may contain several. What the activities are, and howmany there are depends, of course, on the application and its de
17、sign. Typically, oneof the activities is marked as the first one that should be presented to the user whenthe application is launched. Moving from one activity to another is accomplished byhaving the current activity start the next one.Each activity is given a default window to draw in. Typically, t
18、he window fills thescreen, but it might be smaller than the screen and float on top of other windows. Anactivity can also make use of additional windowsfor example, a pop-up dialogthat calls for a user responsein the midst of the activity, or a window that presents users with vital informationwhen t
19、hey select a particular item on-screen.The visual content of the window is provided by a hierarchy of viewsobjects derived from the base View class. Each view controls a particularrectangular space within the window. Parent views contain and organize the layoutof their children. Leaf views (those at
20、 the bottom of the hierarchy) draw in therectangles they control and respond to user actions directed at that space. Thus,views are where the activitys 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 h
21、as a number of ready-made viewscheck boxes, and more.method. The content view is the View object at(See the separate User Interface document for moreinformation on views and the hierarchy.)ServicesA service doesnt have a visual user interface, but rather runs in the backgroundfor an indefinite perio
22、d of time. For example, a service might play background musicas the user attends to other matters, or it might fetch data over the network orcalculate something and provide the result to activities thatneed it. Each serviceextends the Service baseclass.A prime example is a media player playing songs
23、 from a play list. The playerapplication would probably have one or more activities that allow the user to choosesongs and start playing them. However, the musicthat you can useincludingbuttons, text fields,scroll bars, menuitems,A view hierarchyis placed within an activityswindow by theActivity.set
24、ContentView()the root of the hierarchy.playback itself would not be handled by an activity because users will expect themusic to keep playing even after they leave the player and begin somethingdifferent. To keep the music going, the media player activity could start a service torun in the backgroun
25、d. The system would then keep the music playback servicerunning even after the activity that started it leaves the screen.Its possible to connect to (bind to) an ongoing service (and start the service ifits not already running). While connected, you can communicate with the servicethrough an interfa
26、ce that the service exposes. For the music service, this interfacemight 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 wont block other components or the user interface,the
27、y often spawn another thread for time-consuming tasks (like music playback).See Processes and Threads, later.Broadcast receiversA broadcast receiver is a component that does nothing but receive and react tobroadcast announcements. Many broadcasts originate in system codeforexample, announcements tha
28、t 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 broadcastsforexample, to let other applications know that somedata has been downloaded to thedevice and is available for them to use.An app
29、lication can have any number of broadcast receivers to respond to anyannouncements it considers important. All receivers extend the BroadcastReceiverbase class.Broadcast receivers do not display a user interface. However, they maystart anactivity in response to the information they receive, or they
30、may use theNotificationManager to alert the user. Notifications can get the users attention invarious waysflashing the backlight, vibrating the device, playing a sound, and soon. They typically place a persistent icon in the status bar, which users can open toget the message.Content providersA conte
31、nt provider makes a specific set of the applications data available toother applications. The data can be stored in the file system, in an SQLite database,or in any other manner that makessense. The content provider extends theContentProvider base class to implement a standard set of methods that en
32、ableother applications to retrieve and store data of the type it controls. However,applications do not call these methods directly. Rather they use a ContentResolverobject and call its methods instead. A ContentResolver can talk to any contentprovider; it cooperates with the provider to manage any i
33、nterprocesscommunication thats involved.See the separate Content Providers document for more information on usingcontent providers.Whenever theres a request that should be handled by a particular component,Android makes sure that the application process of the component is running,starting it if nec
34、essary, and that an appropriate instance of the component isavailable, creating the instance if necessary.Key Skills & ConceptsCreating new Android projectsWorking with ViewsUsing a TextViewModifying the main.xml fileCreating Your First Android Project in EclipseTo start your first Android proje
35、ct, open Eclipse. When you openEclipse for the first time, it opens to an empty development environment (see Figure5-1), which is where you want to begin. Your first task is to set up and name theworkspace for your application. Choose File | New | Android Project, which willlaunch the New Android Pr
36、oject wizard.CAUTION Do not select Java Project from the New menu. While Androidapplications are written in Java, and you are doing all of your development in Javaprojects, this option will create a standard Java application. Selecting AndroidProject enables you to create Android-specific applicatio
37、ns.If you do not see theoption for Android Project, this indicates that the Android plugin for Eclipse was notfully or correctly installed. Review the procedure in Chapter 3 for installing theAndroid plugin for Eclipse to correct this.The New Android Project wizard creates two things for youA shell
38、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 theAndroid libraries and packages, and also lets you debug your applications in theproper environment.Your first shell files for the new project
39、. These shell files contain someof thevital application blocks upon which you will be building your programs. In much thesame way as creating a Microsoft .NET application in Visual Studio generatessomeWindows-created program code in your files, using the Android Project wizardin Eclipse generates your initial program files and someAndroid-created code. Inaddition, the NewAndroid Project wizard contains a few options, shown next, thatyou must set to initiate your Android project. For the Project Name field, forpurposes of this example, use the title HelloWorldText. This name sufficientlydi
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 壽險營銷活動方案
- 家教公司策劃方案
- 寵物美容活動方案
- 室內cs活動方案
- 寵物營銷活動方案
- 小學五查五看活動方案
- 室內露營展會活動方案
- 寶石活動策劃活動方案
- 憲法知識進學校活動方案
- 安徽濕地活動方案
- 古代漢語專題-003-國開機考復習資料
- 健身房物業保潔及安保服務實施方案
- 檢察機關保密知識培訓
- 3D打印技術與應用知到智慧樹期末考試答案題庫2024年秋西北工業大學
- 《常州紅梅公園》課件
- 軟件正版化工作培訓
- Dahua大華7系報警柱快速操作手冊
- 2024年公司現金管理制度(三篇)
- 04事理說明文閱讀-2022-2023學年八年級語文下冊知識梳理與能力訓練
- 2025高考物理步步高同步練習必修3練透 帶電粒子在電場中的運動
- 2024人形機器人產業半年研究報告
評論
0/150
提交評論