Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Основы программирования на Java. Программирование для Android Android: Введение Кузнецов Андрей Николаевич Санкт-Петербургский Государственный Политехнический Университет 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 1 Инструментарий Разработчика • Android SDK r21 – http://developer.android.com/sdk/index.html • Eclipse IDE for Mobile Developers – http://eclipse.org/mobile/ • ADT Plugin для Eclipse – https://dl-ssl.google.com/android/eclipse/ • Java SE Development Kit 7 – http://www.oracle.com/technetwork/java/javase/ downloads/jdk7-downloads-1880260.html 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 2 Android SDK (1) • SDK Tools (<sdk>/tools/) – Contains tools for debugging and testing, plus other utilities that are required to develop an app. • SDK Platform-tools (<sdk>/platform-tools/) – Contains platform-dependent tools for developing and debugging your application. These tools support the latest features of the Android platform and are typically updated only when a new platform becomes available. • Documentation (<sdk>/docs/) – An offline copy of the latest documentation for the Android platform APIs. See http://developer.android.com/sdk/exploring.html 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 3 Android SDK (2) • SDK Platform (<sdk>/platforms/<androidversion>/) – There's one SDK Platform available for each version of Android. In order to build an Android app, you must specify an SDK platform as your build target. • System Images (<sdk>/platforms/<androidversion>/) • Sources for Android SDK (<sdk>/sources/) • Samples for SDK (<sdk>/platforms/<androidversion>/samples/) • Android Support & Google APIs See http://developer.android.com/sdk/exploring.html 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 4 Android SDK Tools • Android – Lets you manage AVDs, projects, and the installed components of the SDK. • Dalvik Debug Monitor Server (ddms) – Lets you debug Android applications. • Android Emulator (emulator) • Monkey – Runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. • Monkeyrunner – Provides an API for writing programs that control an Android device or emulator from outside of Android code. • И многое другое ... See http://developer.android.com/tools/help/index.html 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 5 Android SDK Platform Tools • Android Debug Bridge (adb). – Android Debug Bridge is a versatile tool that lets you manage the state of an emulator instance or Androidpowered device. You can also use it to install an Android application (.apk) file on a device. – The Android SDK provides additional shell tools that can be accessed through adb, such as bmgr and logcat. • The other platform tools, such as aidl, aapt, dexdump, and dx, are typically called by the Android build tools or Android Development Tools (ADT), so you rarely need to invoke these tools directly. As a general rule, you should rely on the build tools or the ADT plugin to call them as needed. See http://developer.android.com/tools/help/index.html 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 6 Архитектура ОС Android See http://www.android-app-market.com/android-architecture.html 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 7 Linux Kernel • The basic layer is the Linux kernel. The whole Android OS is built on top of the Linux 2.6 Kernel with some further architectural changes made by Google. It is this Linux that interacts with the hardware and contains all the essential hardware drivers. Drivers are programs that control and communicate with the hardware. For example, consider the Bluetooth function. All devices has a Bluetooth hardware in it. Therefore the kernel must include a Bluetooth driver to communicate with the Bluetooth hardware. The Linux kernel also acts as an abstraction layer between the hardware and other software layers. Android uses the Linux for all its core functionality such as Memory management, process management, networking, security settings etc. As the Android is built on a most popular and proven foundation, it made the porting of Android to variety of hardware, a relatively painless task. 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 8 Libraries • The next layer is the Android’s native libraries. It is this layer that enables the device to handle different types of data. These libraries are written in c or c++ language and are specific for a particular hardware. • Some of the important native libraries include the following: • Surface Manager: It is used for compositing window manager with offscreen buffering. Off-screen buffering means you cant directly draw into the screen, but your drawings go to the off-screen buffer. There it is combined with other drawings and form the final screen the user will see. This off screen buffer is the reason behind the transparency of windows. • Media framework: Media framework provides different media codecs allowing the recording and playback of different media formats • SQLite: SQLite is the database engine used in android for data storage purposes • WebKit: It is the browser engine used to display HTML content • OpenGL: Used to render 2D or 3D graphics content to the screen 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 9 Android Runtime • Android Runtime consists of Dalvik Virtual machine and Core Java libraries. • Dalvik Virtual Machine • It is a type of JVM used in android devices to run apps and is optimized for low processing power and low memory environments. Unlike the JVM, the Dalvik Virtual Machine doesn’t run .class files, instead it runs .dex files. .dex files are built from .class file at the time of compilation and provides hifger efficiency in low resource environments. The Dalvik VM allows multiple instance of Virtual machine to be created simultaneously providing security, isolation, memory management and threading support. It is developed by Dan Bornstein of Google. • Core Java Libraries These are different from Java SE and Java ME libraries. However these libraries provides most of the functionalities defined in the Java SE libraries. 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 10 Application Framework • These are the blocks that our applications directly interacts with. These programs manage the basic functions of phone like resource management, voice call management etc. As a developer, you just consider these are some basic tools with which we are building our applications. • Important blocks of Application framework are: • Activity Manager: Manages the activity life cycle of applications • Content Providers: Manage the data sharing between applications • Telephony Manager: Manages all voice calls. We use telephony manager if we want to access voice calls in our application. • Location Manager: Location management, using GPS or cell tower • Resource Manager: Manage the various types of resources we use in our Application 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 11 Applications • Applications are the top layer in the Android architecture and this is where our applications are gonna fit. Several standard applications comes pre-installed with every device, such as: • SMS client app • Dialer • Web browser • Contact manager • As a developer we are able to write an app which replace any existing system app. That is, you are not limited in accessing any particular feature. You are practically limitless and can whatever you want to do with the android (as long as the users of your app permits it). Thus Android is opening endless opportunities to the developer. 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 12 Программные Компоненты Android • • • • • Activities Services Content Providers Broadcast Receivers Intents As a developer we need only to call and extend these already defined classes to use in our application. 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 13 Activities • Class: android.app.Activity • “An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI” - http://developer.android.com 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 14 Services • Class: android.app.Service • “A Service is an application component representing either an application's desire to perform a longer-running operation while not interacting with the user or to supply functionality for other applications to use” - http://developer.android.com • Example: music player application. • All Android services are implemented as a subclass of Service class defined in Android SDK. • There are two types of services in Android: • Unbound Services • Its a type of service which is not bounded to any components. Once started, it will run in the background even after the component that started the service gets killed. It can be run in the background indefinitely and should stop by itself after the operation its intended to carry out is completed. • Bound Services • Its bound to other components and runs only till the component to which it is bounded runs. 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 15 Content Providers • “Content providers are one of the primary building blocks of Android applications, providing content to applications. They encapsulate data and provide it to applications through the single ContentResolver interface. A content provider is only required if you need to share data between multiple applications.” - http://developer.android.com • Example: the contacts data is used by multiple applications and must be stored in a content provider • If you don't need to share data amongst multiple applications you can use a database directly via SQLiteDatabase. 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 16 Broadcast Receivers • Class: android.content.BroadcastReceiver • Broadcast receivers are one of Android application components that is used to receive messages that are broadcasted by the Android system or other Android applications. • Examples: • • • • 13.02.2013 Warning that the battery is getting low Screen turned off Change of time zone The camera has been used to take a picture Creative Commons Attribution-ShareAlike 3.0 17 Intents • • • Class: android.content.Intent “An intent is an abstract description of an operation to be performed. It can be used with startActivity to launch an Activity, broadcastIntent to send it to any interested BroadcastReceiver components, and startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background Service.” - http://developer.android.com Examples: • • • • invoke a new activity from your current activity start other application from your activity By firing an intent, you are telling the Android system to make something happen. There are two types of Intents in Android: • Explicit Intents: • • Implicit Intents: • • 13.02.2013 In explicit Intent, we are highly specific. We specify which activity should get active on receiving the intent. These are usually used for application’s internal communications. In implicit Intent we are sending a message to the Android system to find a suitable Activity that can respond to the intent. Example: send an e-mail Creative Commons Attribution-ShareAlike 3.0 18 Жизненный цикл Android Activity 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 19 Eclipse IDE • DEMO 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 20 Список Источников • http://developer.android.com • http://www.android-appmarket.com/android-architecture.html • http://www.android-appmarket.com/android-applicationcomponents.html 13.02.2013 Creative Commons Attribution-ShareAlike 3.0 21