Android App Development
Outline Introduction Android Fundamentals Android Studio Tutorials
Introduction What is Android? A software platform and operating system for mobile devices Based on the Linux kernel Developed by Android Inc., bought by Google and now managed by the Open Handset Alliance (OHA) Allows writing managed code in the Java language
History of Android
Open Handset Alliance (OHA) Open Handset Alliance, a group of 47 technology and mobile companies have come together to accelerate innovation in mobile and offer consumers a richer, less expensive, and better mobile experience. (from the OHA page)
Architecture
7 The Android Architecture Built on top of Linux kernel (v. 2.6-3.0) Advantages: Portability (i.e. easy to compile on different hardware architectures) Security (e.g. secure multi-process environment) Power Management
8 The Android Architecture Native Libraries (C/C++ code) Graphics (Surface Manager) Multimedia (Media Framework) Database DBMS (SQLite) Font Management (FreeType) WebKit C libraries (Bionic)
9 The Android Architecture Dalvik Virtual Machine (VM) Novel Java Virtual Machine implementation (not using the Oracle JVM) Open License Optimized for memory-constrained devices Faster than Oracle JVM
10 The Android Architecture Application Libraries (Core Components of Android) Activity Manager Packet Manager Telephony Manager Location Manager Contents Provider Notification Manager
11 The Android Architecture Applications (Written in Java code) Android Play Store Entertainment Productivity Personalization Education Geocommunication
But when does the Android version come out? The first blog comment after any ios app is announced.
Why Android Development? Get plugged into the open source platform with the largest market share of smart devices worldwide. The Android SDK is available for Windows, Mac and Linux, so you don t need to pay for new hardware to start writing applications. An SDK built on Java. If you re familiar with the Java programming language, you re already halfway there. By distributing your application on Android Market, it s available to hundreds of thousands of users instantly As well as the technical SDK documentation, new resources are being published for Android developers as the platform gains popularity among both users and developers.
The Big Picture!! Write the code in Java and design layouts in XML files. Once the app is ready, use a build tool to compile all the project files and package them together into.apk file that can be run on Android devices and/or submit to Google Play. All of the files used to put the app together are managed by an Integrated Development Environment (IDE). The standard IDE for Android used to be Eclipse, but this is now being replaced by Google s own Android Studio.
Application Fundamentals Activities application presentation layer Services invisible components, update data sources, visible activities, trigger notifications perform regular processing even when app is not active or invisible Content Providers shareable data store Intents message passing framework broadcast messages system wide, for an action to be performed Broadcast receivers consume intent broadcasts lets app listen for intents matching a specific criteria like location Notifications Toast notification Status Bar Notification Dialog notification
Creating Android App (1) Creating Android app project in Android Studio: Go to File New Project Enter app, project name Choose package name using reverse URL notation, e.g., edu.osu.myapp Select APIs for app, then click Next 16
Creating Android App (2) Determine what kind of Activity to create; then click Next We ll choose a Blank Activity for simplicity Enter information about your Activity, then click Finish This creates a Hello World app 17
Deploying the App Two choices for deployment: Real Android device Android virtual device Plug in your real device; otherwise, create an Android virtual device Emulator is slow. Try Intel accelerated version, or perhaps http://www.genymotion.com/ Run the app: press Run button in toolbar 18
Main Activity Source Code
XML Used to define some of the resources Layouts (UI) Strings Manifest file Shouldn t usually have to edit it directly, Eclipse can do that for you Preferred way of creating UIs Separates the description of the layout from any actual code that controls it Can easily take a UI from one platform to another
XML File
App Manifest Every Android app must include an AndroidManifest.xml file describing functionality The manifest specifies: App s Activities, Services, etc. Permissions requested by app Minimum API required Hardware features required, e.g., camera with autofocus External libraries to which app is linked, e.g., Google Maps library 22
Manifest File
Android Programming Notes Android apps have multiple points of entry: no main() method Cannot sleep in Android During each entrance, certain Objects may be null Defensive programming is very useful to avoid crashes, e.g., if (!(myobj == null)) { // do something } Java concurrency techniques are required Don t block the main thread in Activities Implement long-running tasks such as network connections asynchronously, e.g., as AsyncTasks Recommendation: read [4]; chapter 20 [10]; [11] Logging state via android.util.log throughout app is essential when debugging (finding root causes) Better to have too many permissions than too few Otherwise, app crashes due to security exceptions! Remove unnecessary permissions before releasing app to public Event handling in Android GUIs entails many listener Objects 24