版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、AndroidAndroid, as a system, is a Java-based operating system that runs on the Linuxkernel. The system is very lightweight and full featured. Android applications aredeveloped using Java and can be ported rather easily to the new platform. If you havenot yet downloaded Java or are unsure about which
2、 version you need, I detail theinstallation of the development environment in Chapter 2. Other features of Androidinclude an accelerated 3-D graphics engine (based on hardware support), databasesupport powered by SQLite, and an integrated web browser.If you are familiar with Java programming or are
3、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 the newer,XML-based UI layout. XML UI layout i
4、s a fairly new concept to the average desktopdeveloper. I will cover both the XML UI layout and the programmatic UI development inthe supporting chapters of this book.Oneof the more exciting and compelling features of Android is that, because of itsarchitecture, third-party applicationsincluding tho
5、sethat are“home grown”are executed with the same system priority as those that arebundled with the core system. This is a major departure from most systems, which giveembedded system apps a greater execution priority than the thread priority available toapps created by third-party developers. Also,
6、each application is executed within itsownthread using a very lightweight virtual machine.Aside from the very generous SDK and the well-formed libraries that are availableto us to develop with, the most exciting feature for Androiddevelopers is that we now have access to anything the operating syste
7、m has access to.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 intriguing
8、 applicationsis 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 Androidapplications will be able to tie their applications into existing Google offerings such asGoogle Maps
9、 and the omnipresent Google Search. Suppose you want to write anapplication that pulls up a Google mapof where an incoming call is emanating from, oryou want to be able to store common search results with your contacts; the doors ofpossibility have been flung wide open with Android.Chapter 2 begins
10、your journey to Android development. You will learn the howsand whys of using specific development environments or integrated developmentenvironments (IDE), and you will download and install the Java IDE Eclipse.Application ComponentsA central feature of Android is that one application can make use
11、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 than d
12、evelop your own. Your application doesntincorporate the code of the other application or link to it. Rather, it simply starts up thatpiece of the other application when the need arises.For this to work, the system must be able to start an application process when anypart of it is needed, and instant
13、iate the Java objects for that part. Therefore, unlikeapplications on most other systems, Android applications dont have a single entrypoint for everything in the application (no main() function, for example). Rather, theyhave essential components that the system can instantiate and run as needed. T
14、hereare four types of components:ActivitiesAn activity presents a visual user interface for one focused endeavor the user canundertake. For example, an activity might present alist ofmenu items users can choose from or it might display photographs along with theircaptions. A text messaging applicati
15、on might have one activity that shows a list ofcontacts to send messages to, a second activity to write the message to the chosencontact, and other activities to review old messages or change settings. Though theywork together to form a cohesive user interface, each activity is independent of theoth
16、ers. Each one is implemented 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 design.
17、 Typically, one ofthe activities is marked as the first one that should be presented to the user when theapplication is launched. Moving from one activity to another is accomplished by havingthe current activity start the next one.Each activity is given a default window to draw in. Typically, the wi
18、ndow 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 dialog thatcalls for a user response in the midst of the activity, or a window that presents userswith vital information when they
19、select a particular item on-screen.The visual content of the window is provided by a hierarchy of viewsobjectsderived from the base View class. Each view controls a particular rectangular spacewithin the window. Parent views contain and organize the layout of their children. Leafviews (those at the
20、bottom of the hierarchy) draw in the rectangles they control andrespond to user actions directed at that space. Thus, views are where the activitysinteraction 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
21、number of ready-made views that you can useincluding buttons, text fields, scroll bars, menuitems, check boxes, and more.A view hierarchy is placed within an activityswindow by the () method.The content view is the View object at the root of the hierarchy. (See the separate UserInterface document fo
22、r more information on views and the hierarchy.)ServicesA service doesnt have a visual user interface, but rather runs in the backgroundfor an indefinite period of time. For example, a service might play background music asthe user attends to other matters, or it might fetch data over the network or
23、calculatesomething and provide the result to activities that need it. Each service extends theService base class.A prime example is a media player playing songs from a play list. The playerapplication would probably have one or more activities that allow the user to choosesongs and start playing the
24、m. However, the musicplayback itself would not be handled by an activity because users will expect the musicto keep playing even after they leave the player and begin something different. To keepthe music going, the media player activity could start a service to run in the background.The system woul
25、d then keep the music playback service running even after the activitythat started it leaves the screen.Its possible to connect to (bind to) an ongoing service (and start the service if itsnot already running). While connected, you can communicate with the service throughan interface that the servic
26、e exposes. For the music service, this interface might allowusers 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,they often spawn anot
27、her 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 tobroadcast announcements. Many broadcasts originate in system codefor example,announcements that the timezone has
28、 changed, that the battery is low, that a picturehas been taken, or that the user changed a language preference. Applications can alsoinitiate broadcastsforexample, to let other applications know that somedata has been downloaded to thedevice and is available for them to use.An application can have
29、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 may use theNotific
30、ationManager to alert the user. Notifications can get the users attention invarious waysflashing 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 themessage.Content providersA content provider makes
31、a specific set of the applications data available to otherapplications. The data can be stored in the file system, in an SQLite database, or in anyother manner that makessense. The content provider extends the ContentProviderbase class to implement a standard set of methods that enable other applica
32、tions toretrieve and store data of the type it controls. However, applications do not call thesemethods directly. Rather they use a ContentResolver object and call its methodsinstead. A ContentResolver can talk to any content provider; it cooperates with theprovider to manage any interprocess commun
33、ication 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 itif necessary, and that
34、an appropriate instance of the component is available, creatingthe instance if necessary.Key Skills & ConceptsCreating new Android projectsWorking with ViewsUsing a TextViewModifying the fileCreating Your First Android Project in EclipseTo start your first Android project, open Eclipse. When you ope
35、n Eclipse for thefirst time, it opens to an empty development environment (see Figure 5-1), which iswhere you want to begin. Your first task is to set up and name the workspace for yourapplication. Choose File | New | Android Project, which will launch the New AndroidProject wizard.CAUTION Do not se
36、lect 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 Android Project enables you to create Android-specific you do not see theoption for Android Pro
37、ject, this indicates that the Android plugin for Eclipse was not fullyor correctly installed. Review the procedure in Chapter 3 for installing the Androidplugin for Eclipse to correct this.The New Android Project wizard creates two things for youA shell application that ties into the Android SDK, us
38、ing the file, and ties theproject into the Android Emulator. This allows you to code using all of the Androidlibraries and packages, and also lets you debug your applications in the properenvironment.Your first shell files for the new project. These shell files contain someof the vitalapplication bl
39、ocks upon which you will be building your programs. In much the sameway as creating a Microsoft .NET application in Visual Studio generatessomeWindows-created program code in your files, using the Android Project wizard inEclipse generates your initial program files and someAndroid-created code. In addition,the NewAndroid Project wizard contains a few options, shown next, that you must setto initiate your Android project. For the Project Name field, for purposes of this example,use the title HelloWorldText. This name sufficientl
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 电子元器件冷链物流行业相关项目经营管理报告
- 智能家居远程控制行业营销策略方案
- 太阳能汽车行业发展规模预测与投资潜力研究报告
- 工业用水处理行业相关项目现状分析及对策
- 绿色包装材料行业竞争分析及发展前景预测报告
- 数字版权保护行业的消费市场分析
- 在线儿童成长教育行业市场特点分析
- 物联网智能工业自动化行业市场突围建议书
- 无人驾驶货车物流行业分析报告及未来三年行业发展报告
- 在线AI教育行业分析报告及未来五年行业发展报告
- 人教版地理八年级上册第三节《民族》教学设计3
- 人教版地理七年级上册第四章第二节《世界的语言和宗教》教学设计
- 2024天津滨海新区轨道交通投资发展限公司校园招聘4人(高频重点提升专题训练)共500题附带答案详解
- 项目验收咨询合作
- 2024-2030年中国人造板表面装饰板行业市场深度研究及投资战略规划报告
- 个体商户分红合同范本
- 2024国家卫生健康委干部培训中心事业单位招聘7人历年(高频重点提升专题训练)共500题附带答案详解
- 【北师大版】六年级下册《劳动实践指导手册》第3课《个性房间我装扮》教案
- 2024年全国普通高等学校名单-河南省(174所)
- 生活垃圾清运服务投标方案(技术标)
- 澳门回归25周年课件
评论
0/150
提交评论