The World of Android Development Java Concepts
The Big Difference WEB APPS & MOBILE APPS
Advantages of Web apps o Universal access Browsers are everywhere Any device on the network can access content PCs, Macs, Linux, Android, iphone, Blackberry, etc. o Automatic updates Content comes from server, so is never out of date o Well-established tools and methodologies In multiple languages Java, PHP,.NET, Groovy/Grails, Ruby/Rails, CGI, etc.
Disadvantages of Web app o Few and weak GUI controls Textfield, text area, button, checkbox, radio, list box, combo box. That s it! No direct drawing (except for HTML5 Canvas) o Cannot interact with local resources Cannot read files, call programs, or access devices on the user s machine o Inefficient communication HTTP is weak protocol o Hard to write Requires knowledge of many technologies Java, HTML, HTTP, CSS, JavaScript, jquery, XML Designed for large displays with mouse So harder to use on small phone displays with touch screen
Advantages of Mobile Apps o Many GUI controls Textfield, text area, button, checkbox, radio, list box, combo box, clock, calendar, date picker, dialog box, image gallery, etc. Comparable to options in desktop programming Supports direct drawing So animated games like Angry Birds possible o Can interact with local resources Can read files (e.g., contacts list), have local database, access GPS, initiate phone calls, get input from microphone, create voice output, read screen orientation, etc.
Advantages of Mobile Apps o Efficient communication Can use any networking protocols you want o Easier (?) to write Requires knowledge of one language only Java for Android Objective C for iphone o Designed for small displays with touch screen So, many apps and GUI controls are optimized for this environment
Disadvantages of Mobile Apps o No universal access Apps must be installed one at a time on each phone An Android app cannot run on iphone, Blackberry, PC, Mac, or Linux box o Difficult to manage updates User must intervene to get latest versions o Newer (esp. Android) So, fewer established tools and methodologies On the other hand, Android programming is similar to desktop Java programming, and there are plenty of established approaches there
Current Mobile OS Trend MOBILE MARKET
J2ME o Java Platform, Micro Edition (Java ME) o Provides a robust, flexible environment for applications running on embedded and mobile devices in the Internet of Things: micro-controllers, sensors, gateways, mobile phones, personal digital assistants (PDAs), TV set-top boxes, printers and more. o Includes flexible user interfaces, robust security, built-in network protocols, and support for networked and offline applications that can be downloaded dynamically o Applications based on Java ME are portable across many devices, yet leverage each device's native
J2ME Problem o Screens are small (you will not get comments like, "is that a 24-inch LCD in your pocket, or...?") o User interface has limited tasks or events o Keyboards, if they exist, are small o Pointing devices, if they exist, are annoying (as anyone who has lost their stylus will tell you) or inexact (large fingers and "multi-touch LCDs can sometimes be...problematic) o CPU speed and memory are tight compared to desktops and servers you may be used to
J2ME Problem o Cannot share videos and images o Third-party integration to tools like camera or GPS is fine but consumes more time o Needs more configuration J2ME will be erased if the batteries are exhausted, manual configuration is required. Phones, however, support the improvement of the region, but it was always fraudulences complaints
Java is the Language o Both J2ME and Android uses Java SDK
General IPhone Problem o General apps iphone has larger selection Android trying to catch up o In-house-developed corporate apps iphone apps can only be installed via the App Store iphone requires you to submit app to the Apple App Store and get approval, even for apps from your own company Unless you jailbreak your phone Android apps can be installed through Google App Store Amazon App Store USB connection from PC Email Corporate Web site
Language Usage o iphone Objective-C Similar to, but not exactly the same as, C++ Virtually no corporate presence for Objective-C, other than for mobile apps o Android Java The single most widely used language inside corporations C/C++ Can call native apps (with some difficulty) via an approach similar to JNI for desktop Java
Operating System Support o iphone Macs o Android Anything with Java and Eclipse Macs PCs Linux Solaris
HISTORY
Mobile Software Development o Phone as just a phone and you need to shop and call your wife! o The Brick The Motorola DynaTAC 8000X was the first commercially available cell phone First marketed in 1983, it was 13 x 1.75 x 3.5 inches in dimension, weighed about 2.5 pounds, and allowed you to talk for a little more than half an hour It retailed for $3,995, plus hefty monthly service fees and per-minute charges.
Mobile Software
Mobile Software o WAP (Wireless Application Protocol) advent of internet + mobiles mobiles with LCD 10-digit segmented display Motorola StarTAC (1996) Nokia 8110 These phones can handle data-intensive operations needed by the internet WAP was created
Android o Android Platform Differences Android is hailed as the first complete, open, and free mobile platform. The first android devices : T-Mobile G1 phone Complete: comprehensive platform secure operating system and built a robust software framework on top that allows for rich application development opportunities
Android Open Very open-source Developers have unprecedented access to the handset features when developing applications Free Android applications are free to develop There are no licensing or royalty fees to develop on the platform. No required membership fees No required testing fees. No required signing or certification fees Android applications can be distributed and commercialized in a variety of ways.
Android Market o This is called Google Store which publishes free android applications o Android was bought by Google in July 2007
The Android Trademark
What is Android? o A free, open source mobile platform o A Linux-based, multi-process, multithreaded OS o Android is not a device or a product o It s not even limited to phones - you could build o a DVR, a handheld GPS, an MP3 player, etc.
Android Architecture o The Android platform is designed to be more faulttolerant than many of its predecessors o The handset runs a Linux operating system, upon which Android applications are executed in a secure fashion o Each Android application runs in its own virtual machine o Android applications are managed code; therefore, they are much less likely to cause the phone to crash, leading to fewer instances of device corruption (also called bricking the phone, or rendering it useless)
Dalvik Virtual Machine
Dalvik Virtual Machine o Each Android application runs in a separate process, with its own instance of the Dalvik virtual machine (VM) o Based on the Java VM, the Dalvik design has been optimized for mobile devices o The Dalvik VM has a small memory footprint and multiple instances of the Dalvik VM can run concurrently on the handset.
Overview of the Architecture
INSTALLATION & CONFIGURATION
Android SDK o Download the desired Android SDK fro this URL: http://developer.android.com/sdk/index.html
Eclipse IDE o The latest Eclipse version to download is Eclipse Luna from this URL: http://eclipse.org/downloads/
Java SDK 7.x o Download the whole Java SDK 7.x installer from the Oracle site: http://www.oracle.com/technetwork/java/javase/download s/index.html
Installation o Install Java SDK 7.x first o There are two ways installing Android and Eclipse together: Separate installations: Download Eclipse Run Eclipse and go to Update site and input the following: https://dl-ssl.google.com/android/eclipse/ Restart Eclipse and Update Android SDK Manager Just download the Android SDK bundle file and just unzip to a directory without tampering the content of the zip file.
Android SDK Manager
Configure Emulator o Create AVD (Android Virtual Device) Specify the configuration of a device emulated by Android Emulator (in Eclipse) Create AVD in Eclipse by going to Window->AVD Manager o (Optional) Use a device Install the drivers Connect device to PC via USB cable Be sure to turn on USB debugging Be sure to turn on Install of Non-market apps Device will be recognized by Eclipse via DDMS
MOBILE CONCERNS
Generating the User Interfaces o Two ways to create GUIs: in XML or in code Declarative route via XML has advantages A lot of your GUI-related work will take place in: res/layout res/values o @id/name_for_component gives you handle for referencing XML declarations in code
Views o Views are building blocks of Activities Examples: Can be as basic as: TextView, EditText, or ListView Fancier views: ImageView, MapView, WebView
Layouts o Controls how Views are laid out FrameLayout : each child a layer LinearLayout : single row or column RelativeLayout : relative to other Views TableLayout : rows and columns AbsoluteLayout : <x,y> coordinates
Layouts
Layouts are Customizable
Layout Parameters o Specify many aspects of what s being rendered Examples: android:layout_height android:layout_width o Tip: start with documentation for a specific View or Layout and then look at what s inherited from parent class
APPLICATION COMPONENTS
Basic Components
Activities o UI portion of an application Typically correspond to one screen in a UI o But, they can: be faceless be in a floating window return a value
Activity Example
Views o Building Blocks of Activities and UI
Views o Can be programmed depending on the requirement:
Services o Faceless components that run in the background Example: music player, network download, etc. o Bind your code to a running service via a remote-able interface defined in an IDL o Can run in your own process or separate process
Services o Can start in 2 ways: by calling startservice() by calling bindservice() to create the service
Service
BroadcastReceivers o Components designed to respond to broadcast messages (called Intents) Can receive broadcast messages from the system: a new phone call comes in there is a change in the battery level or cellid Can receive broadcast from another application o Think of them as a way to respond to external notifications or alarms o Applications can invent and broadcast their own Intents as well
BroadcastReceievers
ContentProviders o Enables sharing of data across applications Examples: address book, photo gallery, etc. o Provides uniform APIs for: querying (returns a Cursor) delete, update, and insert rows o Content is represented by URI and MIME type
ContentProviders
Intents o Think of Intents as a verb and object; a description of what you want done Examples: VIEW, CALL, PLAY, etc. o System matches Intent with Activity that can best provide that service o Activities and BroadcastReceivers describe what Intents they can service in their IntentFilters (via AndroidManifest.xml)
Intent
Intents
Layouts o Controls how views are laid out
Storage Options o Preferences o Flat file o SQLite o ContentProvider
Deployment o Think of.apk files as Android packages o Everything needed for an application is bundled up therein o Basically a glorified ZIP file
Resources o res/layout: declarative layout files o res/drawable: intended for drawing o res/anim: bitmaps, animations for transitions o res/values: externalized values for things like strings, colors, styles, etc. o res/xml: general XML files used at runtime o res/raw: binary files (e.g. sound)
Assets o Similar to Resources o Differences: Read-only InputStream access to assets o Any kind of file o Be mindful of file sizes
Application Lifecycle o Application lifecycle is managed by the system o Application start/stop is transparent to the user o End-user only sees that they are moving between screens o Read documentation for android.app.activity
USER INTERFACE OPTIMIZATION
Jquery Mobile Plugin o jquery Mobile is a touch-friendly web UI development framework that lets you develop mobile web applications that work across smartphones and tablets.