付费下载
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、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 abou
2、t 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 programmi
3、ng or are an OOP developer of any sort, you are likely used to programmatic user interface (UI) developmentthat is, UI placement which is handled directly within the program code. Android, whilerecognizing and allowing for programmatic UI development, also supports the newer, XML-based UI layout. XM
4、L UI layout is a fairly new concept to the average desktop developer. I will cover both the XML UI layout and the programmatic UIdevelopment in the supporting chapters of this book.One of the more exciting and compelling features of Android is that, because ofits architecture, third-party applicatio
5、ns including those that are“ homearegrown ”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 agreater execution prioritythan the thread priorityavailable to apps created bythird-party dev
6、elopers. Also, each application is executed within its own thread usinga 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 Android developers isthat we now have access to anything the
7、 operating system has access to. In otherwords, if you want to create an application that dials the phone, you have access to thephone s dialer; if you want to create an application that utilizes the phoneGPS (if equipped), you have access to it. The potential for developers to createdynamic and int
8、riguing applications is now wide open. s精选文库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 su
9、ch 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 Andr
10、oid.Chapter 2 begins your journey to Android development. You will learn the how and why sof 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 app
11、lication 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
12、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
13、 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 componentsthat the sy
14、stem 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 w
15、ith 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 other2精选文库activities to review old messagesor change settings. Though they work together to form a cohesive us
16、er 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
17、 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 activi
18、ty is given a default window to draw in. Typically, the window fillsthe 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 dialogthat calls for a user response in the midst of the activity, or a
19、window that presentsusers 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 o
20、rganize 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 ima
21、ge 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 co
22、ntent 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 servic
23、e might play background music3精选文库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
24、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 di
25、fferent. 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
26、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, servic
27、es 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). See Processes and Threads, later.Broadcast receiversA broadcast receiver is a component that does
28、 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 broadca
29、sts 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 announcementsit considers important. All receivers extend the BroadcastReceiver base class.Bro
30、adcast receivers do not display a user interface. However, they may start an4精选文库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 devic
31、e, 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 file system, in an SQ
32、Lite 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. Rath
33、er 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 provid
34、ers.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 &a
35、mp; 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 Figur
36、e 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 Android5精选文库Project wizard.CAUTION Do not select Java Project from the New menu. While Android applications are written i
37、n 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 forAndroid Project, this indicates that the Android plugin for Eclipse w
38、as 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 A
39、ndroid Emulator. Thisallows 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. These shell files contain some of the vital application blocks upon which you will be building your p
40、rograms. 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 H
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年高职数字孪生技术(数字孪生应用)试题及答案
- 2025年高职第一学年(工业分析技术)仪器分析阶段测试题及答案
- 2025年中职(烹饪专业)烧烤制作试题及答案
- 2025年大学环境科学(环境规划)试题及答案
- 2025年高职智能设备运行与维护(系统升级维护)试题及答案
- 2025年大学通信技术(设备实操技术)试题及答案
- 2025年高职中药类(中药方剂配伍)试题及答案
- 2025年中职(口腔修复工艺)可摘局部义齿制作试题及答案
- 2025年大学大三(物联网工程)智慧园区技术试题及答案
- 2025年高职智能网联汽车技术(智能网联应用)试题及答案
- 医师手术授权与动态管理制度
- 湖南省长沙市2024年七年级上学期期末数学试卷【附答案】
- 澳洲坚果需肥特性与科学高效施肥技术
- 学习无人机航拍心得体会1000字
- GB/T 23132-2024电动剃须刀
- 公司5S推行管理手册
- 医药产业园区智慧园区系统建设方案
- 2024年煤气购销合同
- 食品质量保证措施方案
- 工厂保安服务投标方案
- 全套医疗器械设计和开发资料(模板可修改)
评论
0/150
提交评论