440 likes | 603 Views
Introduction to Android application development. Narender Ramireddy Technical Lead IBM Chiphopper – Partner Program. Agenda. Android Framework Topics Example – Multiple Activities Data Storage Example – Shared Preferences Example – SQLite Database Location Manager
E N D
Narender Ramireddy Technical Lead IBM Chiphopper – Partner Program
Agenda Android Framework Topics Example – Multiple Activities Data Storage Example – Shared Preferences Example – SQLite Database Location Manager Example – Location Manager Notepad Example API Demos Android Overview Android SDK Example - Hello World XML UI Layout Manifest, Resources and R.java Developing on a device IBM and Android Hear from you Android User Groups in Dallas Area
Pre Requisites Java or any other Object Oriented programming language background. Eclipse or similar IDE experience
Android Overview Android is a software stack for mobile devices that includes an operating system, middleware and key applications. The Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language.
Android Overview Android is a software stack for mobile devices that includes an operating system, middleware and key applications. API 2 API 3 API 4 API 5 API 6 API 7 API 8 API 9 Android 1.1 Android 1.5 Android 1.6 Android 2.0 Android 2.0.1 Android 2.1 Android 2.2 Android 2.3
Phone Hardware Vendors Android x.y Stack Source Code http://source.android.com Android Mobile Device
Installing Android SDK http://developer.android.com Prepare your development computer and ensure it meets the system requirements. Install the SDK starter package. Add Android platforms and other components to your SDK. Install the ADT Plug-in for Eclipse (if you'll be developing in Eclipse).
Android SDK Machine code for ARM QEMU open source machine emulator Virtual ARM Mobile Device Machine code for Target development Platform QEMU open source machine emulator Virtual ARM Mobile Device API tools SDK Starter Kit Emulator
Android SDK Android 1.5 Stack Source Code Android 1.6 Stack Source Code Android 2.3 Stack Source Code Android 1.5 Android 1.6 Android 2.3 Android platforms QEMU open source machine emulator Virtual ARM Mobile Device API tools SDK Starter Kit Emulator
Android Virtual Device ( AVD ) AVD AVD Android 2.3 - API 9 Android 2.2 - API 8 QEMU open source machine emulator QEMU open source machine emulator Virtual ARM Mobile Device Virtual ARM Mobile Device
Creating Android Virtual Devices From Eclipse : Windows Android SDK and AVD Manager Command Line: C:\Program Files\Android\android-sdk-windows\tools>android.bat
Android Dev Guide http://developer.android.com • Android Basics • Framework Topics • Developing • Publishing • Best Practices • Tutorials and Samples • Appendix
Deploy / Run Source Source Source Compile / Build Android Virtual Device (AVD) .apk Deploy / Run Deploy / Run Device
XML GUI - Example • <LinearLayoutxmlns:android=http://schemas.android.com/apk/res/android • android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> • <LinearLayoutandroid:orientation="horizontal" • android:layout_width="match_parent" android:layout_height="wrap_content"> • <TextViewandroid:layout_width="wrap_content" android:layout_height="wrap_content" • android:text="@string/title" /> • <EditTextandroid:id="@+id/title" • android:layout_width="wrap_content" • android:layout_height="wrap_content" • android:layout_weight="1" /> • </LinearLayout> • <TextViewandroid:layout_width="wrap_content" • android:layout_height="wrap_content" • android:text="@string/body" /> • <EditTextandroid:id="@+id/body" • android:layout_width="match_parent" • android:layout_height="wrap_content" • android:layout_weight="1" • android:scrollbars="vertical" /> • <Button android:id="@+id/confirm" • android:text="@string/confirm" • android:layout_width="wrap_content" • android:layout_height="wrap_content" /> • </LinearLayout>
Resources and the R class The folders under res/ in the Eclipse project are for resources. There is a specific structure to the folders and files under res/. A project's R.java file is an index into all the resources defined in the file. Resources defined in these folders and files will have corresponding entries in the R class allowing them to be easily accessed and used from your application. The R class is automatically generated using the contents of the res/ folder by the eclipse plugin (or by aapt if you use the command line tools). Furthermore, they will be bundled and deployed for you as part of the application.
Developing on a Device • Declare your application as "debuggable" in your Android Manifest. • In the AndroidManifest.xml file, add android:debuggable="true" to the <application> element. • Turn on "USB Debugging" on your device. • On the device, go to the home screen, press MENU, select Applications > Development, then enable USB debugging. • You need to install a USB driver for adb • You should see the device in the list by issuing the following command • adb devices For more information go to http://developer.android.com/guide/developing/device.html
process process Unique user ID Unique user ID AVD Android 2.2 - API 8 Hello World App Second App QEMU open source machine emulator Virtual ARM Mobile Device JVM JVM
Application Fundamentals • Application Components • Activating Components • The manifest file • Components Lifecycle • Activities and Tasks • Processes and Threads
Application Components Activity Service Receiver Provider All components run in the main thread of the application process
Activity Component Activity • Implemented as a subclass of the Activity base class • Presents a visual user interface for one focused endeavor the user can undertake • Each activity is independent of the others • An application might consist of just one activity or may contain several • Moving from one activity to another is accomplished by having the current activity start the next one • Each activity is given a default window to draw in • 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 organize the layout of their children. Leaf views draw in the rectangles they control and respond to user actions directed at that space
Service Component Service • Each service extends the Service base class. • A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. • It's possible to connect to (bind to) an ongoing service (and start the service if it's not already running). While connected, you can communicate with the service through an interface that the service exposes.
Receiver Component Receiver • All receivers extend the BroadcastReceiver base class. • Component that does nothing but receive and react to broadcast announcements. • An application can have any number of broadcast receivers to respond to any announcements it considers important. • They may start an activity in response to the information they receive, or they may use the NotificationManager to alert the user.
Provider Component Provider • 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 • A content provider makes a specific set of the application's data available to other applications • Applications do not call the ContentProvider methods directly. Rather 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.
intents : To Activate components • An intent is an Intent object that holds the content of the message • Activities, Services, and Broadcast receivers — are activated by asynchronous messages called intents. • Content providers are activated when they're targeted by a request from a ContentResolver.
The behavior just described is the default behavior for activities and tasks. But there are ways to modify almost all aspects of it. The association of activities with tasks, and the behavior of an activity within a task, is controlled by the interaction between flags set in the Intent object that started the activity and attributes set in the activity's <activity> element in the manifest. Both requester and respondent have a say in what happens.
All components are instantiated in the main thread of the specified process, and system calls to the component are dispatched from that thread