Android SDK introduction <ul><li>Android SDK library distribution according to functionality </li></ul><ul><li>Activity, Services and Broadcast Recievers </li></ul><ul><li>View and related classes, List </li></ul><ul><li>Intents, Adapters, AlertDialouge, Notifications. </li></ul><ul><li>SharedPreferences </li></ul><ul><li>ContentProviders and Databases </li></ul><ul><li>Maps, Geocoding </li></ul><ul><li>Widget </li></ul><ul><li>Multimedia </li></ul><ul><li>Telephony and SMS </li></ul><ul><li>Bluetooth and WiFi </li></ul><ul><li>Sensors </li></ul>
Activity, Services and Broadcast Receivers Activities – The entry class into Android application, responsible for loading the first screen and take user inputs -onCreate() -onDestroy(); -onPause(); -onStart(); Services – The class used to create programs that run in background, and have no UI Broadcast receiver – The android component responsible to receive responses from system wide processes and send the event notification to the registered processes
Views View – Responsible for the UI in the application. A view is put on a layout and then as per programming directives a layout is laid
Intents, Adapters, AlertDialogue and Notifications <ul><li>Intents - Intents are used as a message-passing mechanism that works both within application, and between applications. Intents can be used to: </li></ul><ul><li>Start an Activity or service </li></ul><ul><li>Broadcast an event </li></ul><ul><li>Explicitly start an Activity </li></ul><ul><li>Adapters - Adapters are bridging classes that bind data to Views used in the user interface. And load dynamic data in the UI </li></ul><ul><li>AlertDialouge – To show the user the Alert and seek any response, and then perform any action on it </li></ul><ul><li>Notification - notify the user on any </li></ul><ul><li>event in the notification bar </li></ul><ul><li>. </li></ul>
Content Providers and Data storage <ul><li>Content Providers - Content providers are interfaces to store and retrieve data and make it accessible to all applications. They're the only way to share data across applications </li></ul><ul><li>Data Storage - Android provides several options for you to save persistent application data. The solution you choose depends on your specific needs </li></ul><ul><li>Shared Preferences Store private primitive data in key-value pairs . </li></ul><ul><li>Internal Storage Store private data on the device memory. </li></ul><ul><li>External Storage Store public data on the shared external storage. </li></ul><ul><li>SQLite Databases Store structured data in a private database . </li></ul><ul><li>Network Connection Store data on the web with your own network server. </li></ul>
Data storage methods in brief <ul><li>Shared preferences - The SharedPreferences class provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types </li></ul><ul><li>getSharedPreferences(), getPreferences() – use these methods to obtain multiple or single preferences for the application respectively . </li></ul><ul><li>Edit() or putBoolean(), putString() etc – use the former method to use SharedPreference.Editor, and later methods to directly specify and enter the data </li></ul><ul><li>Internal Storage - We can save files directly on the device's internal storage, by using the FileStream class and its methods – write() and read() etc. </li></ul><ul><li>External Storage – The external storage device in Android mobiles is the SD card. We can save and retrieve data on SD card using some of the methods – </li></ul><ul><li>getExternalStorageState() – to check the availability and status of SD card </li></ul><ul><li>getExternalStorageDirectory() – to open the file which represent the root of the external storage file system. </li></ul>
SQLite Database Android provides full support for SQLite databases. Any databases you create will be accessible by name to any class in the application, but not outside the application. To create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database. getWritableDatabase() and getReadableDatabase() To write and read from database, their return type is SQLiteDatabase class that provides methods for database operations . SQLiteDatabase query() methods – to execute queries, these methods takes various parameters, for various quires. Cursor It’s the return type of any SQLite query and the mechanism with which you can navigate results from a database query and read rows and columns .
Maps and GeoCoding <ul><li>Important classes related to GPS capabilities in Android </li></ul><ul><li>LocationManager - This class provides access to the system location services. These services allow applications to obtain periodic updates of the device's geographical location. </li></ul><ul><li> getLastKnownLocation(provider); </li></ul><ul><li>Proximity alert setting </li></ul><ul><li>Geocoding - Geocoding is the process of transforming a street address or other description of a location into a (latitude, longitude) coordinate. Reverse geocoding is the process of transforming a (latitude, longitude) coordinate into a (partial) address. </li></ul><ul><li> Geocoder(Context context, Locale locale) </li></ul><ul><li> Geocoder(Context context) </li></ul>
Android App Widgets App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates. AppWidgetProviderInfo object Describes the metadata for an App Widget. AppWidgetProvider class implementation Defines the basic methods that allow you to programmatically interface with the App Widget, based on broadcast events. onUpdate() onDeleted(Context, int) onEnabled(Context) onReceive(Context, Intent) View class to draw the widget layout
Multimedia content Multimedia playback in Android is handled by the MediaPlayer class. You can play media stored in application resources, local files, Content Providers, or streamed from a network URL create(appContext, R.raw.my_audio); setDataSource("/sdcard/test2.3gp"); prepare(); For playing Video, we have to use a VideoView to act a surface to display the video MediaRecorder class and associated methods are used for recording video Using Intents Actions we can use camera and audio recording features
Telephony and SMS <ul><li>Provides APIs for monitoring the basic phone information, such as the network type and connection state, plus utilities for manipulating phone number strings. </li></ul><ul><li>CellLocation, NeighboringCellInfo </li></ul><ul><li>PhoneNumberUtils </li></ul><ul><li>PhoneStateListener </li></ul><ul><li>ServiceState . </li></ul><ul><li>SignalStrength . </li></ul><ul><li>TelephonyManager </li></ul><ul><li>SmsManager - Manages SMS operations such as sending data, text, and pdu SMS messages. Get this object by calling the static method SmsManager.getDefault() </li></ul><ul><li>sendTextMessage() – to send text SMS </li></ul>
Bluetooth and WiFi <ul><li>Using the Bluetooth APIs, an Android application can perform the following: </li></ul><ul><ul><li>Scan for other Bluetooth devices </li></ul></ul><ul><ul><li>Query the local Bluetooth adapter for paired Bluetooth devices </li></ul></ul><ul><ul><li>Connect to other devices through service discovery </li></ul></ul><ul><ul><li>Transfer data to and from other devices </li></ul></ul><ul><ul><li>Manage multiple connections </li></ul></ul><ul><ul><li>BluetoothAdapter - The BluetoothAdapter is the entry-point for all Bluetooth interaction. </li></ul></ul><ul><ul><li>BluetoothDevice - Represents a remote Bluetooth device. </li></ul></ul><ul><ul><li>BluetoothSocket - This is the connection point that allows an application to exchange data with another Bluetooth device via InputStream and OutputStream. </li></ul></ul><ul><ul><li>BluetoothServerSocket - - Represents an open server socket that listens for incoming requests (similar to a TCP ServerSocket). </li></ul></ul><ul><ul><li>The WifiManager represents the Android Wi-Fi Connectivity Service. It can be used to configure Wi-Fi network connections, manage the current Wi-Fi connection, scan for access points, and monitor changes in Wi-Fi connectivity </li></ul></ul>
Android Booting Sequence Stages In Booting of Android OS from power on Stage 1 : Power on and boot ROM code execution Stage 2 : The boot loader loading Stage 3 : Starting of Linux kernel Stage 4 : The init process Stage 5 : Zygote and Dalvik Stage 6 : The system server initiation
Android Booting Sequence Stage 1 Power on and boot ROM code execution <ul><li>At power on the CPU will be in a state where no initializations have been done. Internal clocks are not set up and the only memory available is the internal RAM. </li></ul><ul><li>When power supplies are stable the execution will start with the Boot ROM code. The Boot ROM code will detect the boot media using a system register that maps to some physical balls on the ASIC. This is to determine where to find the first stage of the boot loader. </li></ul><ul><li>Once the boot media sequence is established the boot ROM will try to load the first stage boot loader to internal RAM. Once the boot loader is in place the boot ROM code will perform a jump and execution continues in the boot loader. </li></ul>
Android Booting Sequence Stage 2 The boot loader loading <ul><li>The first boot loader stage will detect and set up external RAM. </li></ul><ul><li>Once external RAM is available and the system is ready the to run something more significant the first stage will load the main boot loader and place it in external RAM. </li></ul><ul><li>The second stage of the boot loader is the first major program that will run. This may contain code to set up file systems, additional memory, network support, loading code for the modem CPU and setting up low level memory protections and security options. </li></ul><ul><li>Once the boot loader is done with any special tasks it will look for a Linux kernel to boot. It will load this from the boot media (or some other source depending on system configuration) and place it in the RAM. </li></ul><ul><li>Once the boot loader is done it will perform a jump to the Linux kernel, usually some decompression routine, and the kernel assumes system responsibility </li></ul>
Android Booting Sequence Stage 3 Starting of Linux kernel <ul><li>It will set up everything that is needed for the system to run. Initialize interrupt controllers, set up memory protections, caches and scheduling. </li></ul><ul><li>Once the memory management units and caches have been initialized the system will be able to use virtual memory and launch user space processes. </li></ul><ul><li>The kernel will look in the root file system for the init process (found under system/core/init in the Android open source tree) and launch it as the initial user space process. </li></ul>
Android Booting Sequence Stage 4 The init process <ul><li>The init process in Android will look for a file called init.rc. This is a script that describes the system services, file system and other parameters that need to be set up. The init.rc script is placed in system/core/rootdir in the Android open source project. </li></ul><ul><li>The init process will parse the init script and launch the system service processes. </li></ul>
Android Booting Sequence Stage 5 Zygote and Dalvik <ul><li>init runs the C++ program /system/bin/app_process, and gives the resulting process the name "zygote“ </li></ul><ul><li>app_process executes, and executes a runtime environment for a dalvik class </li></ul><ul><li>app_process does a 'runtime.start("com.android.internal.os.ZygoteInit", startSystemServer) </li></ul><ul><li>com.android.internal.os.ZygoteInit:main() starts executing </li></ul><ul><li>The profiler is started the Zygote socket is registered (for later communication to start apps) classes and resources are preloaded if startSystemServer is set, then the system server is started </li></ul><ul><li>Zygote runs in "select loop mode", where a single process spins waiting for communication to start subsequent apps. </li></ul><ul><li>Eventually, a call is made to Zygote.forkAndSpecialize(), which does the actual forking </li></ul>
Android Booting Sequence Stage 6 The system server initiation The system server is the first java component to run in the system. It will start all the Android services such as telephony manager and bluetooth. Start up of each service is currently written directly into the run method of the system server. source can be found in the file frameworks/base/services/java/com/android/server/SystemServer.java in the open source project. Once the System Server is up and running and the system boot has completed there is a standard broadcast action called ACTION_BOOT_COMPLETED. To start your own service, register an alarm or otherwise make your application perform some action after boot you should register to receive this broadcast intent .
Steps for setting up Android application development environment <ul><li>Basic System requirements </li></ul><ul><li>Supported Operating Systems </li></ul><ul><ul><li>Windows XP (32-bit), Vista (32- or 64-bit), or Windows 7 (32- or 64-bit) </li></ul></ul><ul><ul><li>Mac OS X 10.5.8 or later (x86 only) </li></ul></ul><ul><ul><li>Linux (tested on Ubuntu Linux, Lucid Lynx) </li></ul></ul><ul><li>Supported Development Environments </li></ul><ul><li>Eclipse IDE </li></ul><ul><li>JDK 5 or JDK 6 (JRE alone is not sufficient) </li></ul><ul><li>Android Development Tools plugin (recommended) </li></ul><ul><li>Not compatible with Gnu Compiler for Java (gcj) </li></ul><ul><li>Other development environments or IDEs </li></ul><ul><li>Apache Ant 1.8 or later </li></ul>
<ul><li>Open the Eclipse IDE, click on the tab "Workbench", this will take you to the work bench. </li></ul><ul><li>Go to Help -> Install New Software </li></ul>
3. Now in the work with tab, click on Add button, and then follow the instructions given in the ADT(Android Development Tool) installation link - The ADT URL is - follow the instructions in the installation, and then you must see the following screen. Then click on next, and then let the installation finish.
4 . Once the IDE has restarted, go to Window -> Preferences. Then click on the "Android" tab on the screen coming on the left hand side
Then, again go to Windows -> Android Device and AVD manager, then click on Available packages tab, in the list coming on the left hand side of the screen, in the main window, a list of currently available Android version and other extensions for development of Samsung Galaxy Tab device application development will be shown
Set up AVD An Android Virtual Device (AVD) is an emulator configuration that lets you model an actual device by defining hardware and software options to be emulated by the Android Emulator
<ul><li>A hardware profile : Defines the hardware features of the virtual device. For example, you can define whether the device has a camera, whether it uses a physical QWERTY keyboard or a dialing pad, how much memory it has, </li></ul><ul><li>A mapping to a system image: You can define what version of the Android platform will run on the virtual device. You can choose a version of the standard Android platform or the system image packaged with an SDK add-on. </li></ul><ul><li>Other options : You can specify the emulator skin you want to use with the AVD, which lets you control the screen dimensions, appearance, and so on. You can also specify the emulated SD card to use with the AVD. </li></ul><ul><li>A dedicated storage area on your development machine: the device's user data (installed applications, settings, and so on) and emulated SD card are stored in this area . </li></ul>Features of AVD
<ul><li>Go to Windows -> Android Device and AVD manager -> Virtual devices. Then click on the "New" tab on the left side of the screen. This will pop a device box, which will ask for details of the AVD. </li></ul><ul><li>Select your SDK, and the functionalities you want to include in your device - this includes - Camera, internet, SD card, GPS etc and all the functionalities supported by Android APIs. Once done, click on "Create Device" tab. </li></ul>Steps to setup AVD
What you can do with AVD <ul><li>Emulate SD card </li></ul><ul><li>Emulate GPS, accelerometer, camera, video recorder etc </li></ul><ul><li>Run internet </li></ul><ul><li>Load applications inside the emulated SD card. </li></ul><ul><li>Enter real time data </li></ul><ul><li>Use QWERTY key board </li></ul><ul><li>Multiple language support. </li></ul><ul><li>Use native emulator apps like google maps etc. </li></ul><ul><li>Perform real time debugging </li></ul><ul><li>Customize settings and themes. </li></ul>
Debugging Android applications The main components that comprise a typical Android debugging environment are: adb adb acts as a middleman between a device and your development system. It provides various device management capabilities, including moving and syncing files to the emulator, running a UNIX shell on the device or emulator, and providing a general means to communicate with connected emulators and devices. Dalvik Debug Monitor Server DDMS is a graphical program that communicates with your devices through adb. DDMS can capture screenshots, gather thread and stack information, spoof incoming calls and SMS messages, and has many other features. Device or Android Virtual Device Your application must run in a device or in an AVD so that it can be debugged. An adb device daemon runs on the device or emulator and provides a means for the adb host daemon to communicate with the device or emulator.
ADB : Android Debugger bridge <ul><li>Android Debug Bridge (adb) is a versatile tool lets you manage the state of an emulator instance or Android-powered device. It is a client-server program that includes three components: </li></ul><ul><li>A client , which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients. </li></ul><ul><li>A server , which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device. </li></ul><ul><li>A daemon , which runs as a background process on each emulator or device instance. </li></ul><ul><li>You can find the adb tool in <sdk>/platform-tools/. </li></ul>
Emulator 1, console: 5554 Emulator 1, adb: 5555 Emulator 2, console: 5556 Emulator 2, adb: 5557 ... Install Application on ADB - adb install <path_to_apk> Port forwarding - You can use the forward command to set up arbitrary port forwarding adb forward tcp:6100 tcp:7100 adb forward tcp:6100 local:logd File transfer across system and ADB - You can use the adb commands pull and push to copy files to and from an emulator/device instance's data file. adb pull <remote> <local> adb push <local> <remote>
Dalvik Debug Monitor Server : DDMS Android ships with a debugging tool called the Dalvik Debug Monitor Server (DDMS), which provides port-forwarding services, screen capture on the device, thread and heap information on the device, logcat, process, and radio state information, incoming call and SMS spoofing, location data spoofing, and more. Running DDMS DDMS is integrated into Eclipse and is also shipped in the tools/ directory of the SDK. DDMS works with both the emulator and a connected device. If both are connected and running simultaneously, DDMS defaults to the emulator. From Eclipse: Click Window > Open Perspective > Other... > DDMS . From the command line: Type ddms (or ./ddms on Mac/Linux) from the tools/ directory.
<ul><li>When DDMS starts, it connects to adb. When a device is connected, a VM monitoring service is created between adb and DDMS, which notifies DDMS when a VM on the device is started or terminated. Once a VM is running, DDMS retrieves the the VM's process ID (pid), via adb, and opens a connection to the VM's debugger, through the adb daemon (adbd) on the device. DDMS can now talk to the VM using a custom wire protocol. </li></ul><ul><li>DDMS assigns a debugging port to each VM on the device. Typically, DDMS assigns port 8600 for the first debuggable VM, the next on 8601, and so on </li></ul><ul><li>By default, DDMS also listens on another debugging port, the DDMS "base port" (8700, by default). The base port is a port forwarder, which can accept VM traffic from any debugging port and forward it to the debugger on port 8700. </li></ul>ADB - DDMS
Using DDMS <ul><li>Viewing heap usage for a process </li></ul><ul><li>DDMS allows you to view how much heap memory a process is using. This information is useful in tracking heap usage at a certain point of time during the execution of your application. </li></ul><ul><li>To view heap usage for a process: </li></ul><ul><li>In the Devices tab, select the process that you want to see the heap information for. </li></ul><ul><li>Click the Update Heap button to enable heap information for the process. </li></ul><ul><li>In the Heap tab, click Cause GC to invoke garbage collection, which enables the collection of heap data. When the operation completes, you will see a group of object types and the memory that has been allocated for each type. You can click Cause GC again to refresh the data. </li></ul><ul><li>Click on an object type in the list to see a bar graph that shows the number of objects allocated for a particular memory size in bytes. </li></ul>
<ul><li>Tracking memory allocation of objects </li></ul><ul><li>DDMS provides a feature to track objects that are being allocated to memory and to see which classes and threads are allocating the objects. This allows you to track, in real time, where objects are being allocated when you perform certain actions in your application </li></ul><ul><li>To track memory allocation of objects: </li></ul><ul><li>In the Devices tab, select the process that you want to enable allocation tracking for. </li></ul><ul><li>In the Allocation Tracker tab, click the Start Tracking button to begin allocation tracking. At this point, anything you do in your application will be tracked. </li></ul><ul><li>Click Get Allocations to see a list of objects that have been allocated since you clicked on the Start Tracking button. You can click on Get Allocations again to append to the list new objects that that have been allocated. </li></ul><ul><li>To stop tracking or to clear the data and start over, click the Stop Tracking button . </li></ul><ul><li>Click on a specific row in the list to see more detailed information such as the method and line number of the code that allocated the object. </li></ul>
<ul><li>Working with an emulator or device's file system </li></ul><ul><li>DDMS provides a File Explorer tab that allows you to view, copy, and delete files on the device. This feature is useful in examining files that are created by your application or if you want to transfer files to and from the device. </li></ul><ul><li>To work with an emulator or device's file system: </li></ul><ul><li>In the Devices tab, select the emulator that you want to view the file system for. </li></ul><ul><li>To copy a file from the device, locate the file in the File Explorer and click the Pull file button. </li></ul><ul><li>To copy a file to the device, click the Push file button on the File Explorer tab. </li></ul>
Examining thread information The Threads tab in DDMS shows you the currently running threads for a selected process. In the Devices tab, select the process that you want to examine the threads for. Click the Update Threads button. In the Threads tab, you can view the thread information for the selected process.
<ul><li>Starting method profiling </li></ul><ul><li>Method profiling is a means to track certain metrics about a method, such as number of calls, execution time, and time spent executing the method. </li></ul><ul><li>Before you start method profiling in DDMS, be aware of the following restrictions: </li></ul><ul><li>To start method profiling: </li></ul><ul><li>On the Devices tab, select the process that you want to enable method profiling for. </li></ul><ul><li>Click the Start Method Profiling button. </li></ul><ul><li>Interact with your application to start the methods that you want to profile. </li></ul><ul><li>Click the Stop Method Profiling button. DDMS stops profiling your application and opens Traceview with the method profiling information that was collected between the time you clicked on Start Method Profiling and Stop Method Profiling . </li></ul>
<ul><li>Using LogCat </li></ul><ul><li>LogCat is integrated into DDMS, and outputs the messages that you print out using the Log class along with other system messages such as stack traces when exceptions are thrown. View the Reading and Writing Log Messages. topic for more information on how to log messages to the LogCat. </li></ul><ul><li>When you have set up your logging, you can use the LogCat feature of DDMS to filter certain messages with the following buttons: </li></ul><ul><li>Verbose </li></ul><ul><li>Debug </li></ul><ul><li>Info </li></ul><ul><li>Warn </li></ul><ul><li>Error </li></ul><ul><li>You can also setup your own custom filter to specify more details such as filtering messages with the log tags or with the process id that generated the log message. The add filter, edit filter, and delete filter buttons let you manage your custom filters . </li></ul>
Changing network state, speed, and latency Voice - unregistered, home, roaming, searching, denied Data - unregistered, home, roaming, searching, denied Speed - Full, GSM, HSCSD, GPRS, EDGE, UMTS, HSDPA Latency - GPRS, EDGE, UMTS Spoofing calls or SMS text messages Voice - Enter a number in the Incoming number field and click Call to send a simulated call to the emulator or phone. Click the Hang up button to terminate the call. SMS - Enter a number in the Incoming number field and a message in the Message : field and click the Send button to send the message. Setting the location of the phone Manual - set the location by manually specifying decimal or sexagesimal longitude and latitude values. GPX - GPS eXchange file KML - Keyhole Markup Language file
References http://www.developer.android.com What is Android? Android Developers Debugging Managing Virtual Devices Android Debug Bridge App Widgets Data Storage Content Providers Bluetooth Activity ActivityManager Service SharedPreferences Geocoder LocationManager WifiManager SmsManager android.telephony Topics from Android developer website
A particular slide catching your eye?
Clipping is a handy way to collect important slides you want to go back to later.