Introduction to Android Chapter 1 1
Objectives Understand what Android is Learn the differences between Java and Android Java Examine the Android project structure Build a basic application using Android Studio Learn about the Model-View-Controller design 2
Why Mobile Computing? Trends in computing industry Mainframe/batch Workstation/client-server PC/Web/P2P Mobile? New Knowledge Areas (KA) in CS Curricula 2013 Joint work by ACM and IEEE-CS Platform-based Development (PBD), e.g., mobile, web, and game Good addition to your resume? 3
Why Android? Android: Java-based, market dominance (82.8% share in 2015 Q2) IOS: Objective-C Global smartphone OS market share in 2015 Q2 (from 4
What Is Android? Mobile OS by Google Based on Linux kernel Touchscreen devices Direct manipulation UI Touch gestures (swiping, tapping, pinching) Virtual keyboard 5
Evolution of Android 6
Evolution of Android (Cont.) Which version to support? 7
Android Programming Basics Java for most framework Java SDK + Android SDK + IDE (Android Studio or Eclipse) XML for configuration and resources Cursorless control (gestures using fingers) Framework concepts Activities Intents Views and widgets Asynchronous calls Background services … 8
Java vs. Android Java A large number of Java libraries in the Android platform Android SDK: Dalvik compiler, debugger, software libraries, emulator 9
Java API vs. Android API No Java virtual machine in the Android platform Specialized VM, Dalvik and ART (v 5.0) Java bytecode compiled again into a proprietary bytecode, dex bytecode Dex bytecode Java bytecode Dex bytecode: compact Dalvik executable format designed for Android systems, constrained in terms of memory and processor speed. Dalvik dx tool for translating java bytecode into dex bytecode 10
Android Studio Official IDE for building Android applications, including: Java editor, layout editor, Android SDK, emulator, gradle, etc. Focuses exclusively on Android development and comes bundled with the Android Software Development Kit, SDK Android SDK, a set of tools and API libraries for: Building complete applications, Testing them on virtual devices, and Performing debugging and optimization 11
Anatomy of Android Project Organization of Android project Source code Application’s resources Manifest settings Build files All of these files eventually packaged into an apk (distribution) file 12
13
Android Manifest File An AndroidManifest.xml, is required for every Android application. This file uses XML code to define specific application information. This information can include general application- wide settings such as the application’s style and launch icon. 14
AndroidManifest.xml 15 <manifest xmlns:android="..." package="edu.utep.cs.cs4390.helloworld" android:versionCode="1" android:versionName="1.0"> <application <activity android:name=".MainActivity"
Java Source Code The Java source code of an application is placed in the java directory of the project structure. A main file, often named MainActivity, is a Java file that is auto-generated when the project is first created. Can include JUnit test files, local tests and instrumented tests. 16
Drawable Resources The drawable folder is located in the res directory res contains the application resources Drawable resources are image files, such as application icons, buttons, and background textures Q: mipmap vs. drawable folders? Q: how to refer to an XML resource such as a drawable in Java source code? 17
Generalized Screen Size xlarge screens are at least 960dp x 720dp large screens are at least 640dp x 480dp normal screens are at least 470dp x 320dp small screens are at least 426dp x 320dp 18
Layout XML Files User interface screens are visually designed and coded as XML layout files. The design and arrangement of the elements on the screen are implemented using XML code in a layout file. Q: Advantages and disadvantages? Q: How to associate an XML layout with an activity? 19
Example: activity_main.xml 20 <RelativeLayout xmlns:android=" …> <LinearLayout … android:orientation="horizontal"> <Button … android:onClick="startClicked" />
In-class: Timer App To have a taste of Android programming by: Defining a simple UI in XML file (activity_main.xml), Externalizing constants in XML file (strings.xml), Associating UI with activity (setContentView), Retrieving views defined in XML (findViewById), Defining control code for views (android:onClick), Separating model code from view and control. 21
Model-View-Controller Android applications tend to rely on the Model- View-Controller design architecture. This architecture assigns one of three roles that objects can play in an application. 22 Model (data) View (UI element) Control update UI notify change notify user action update data
Sharing Android Apps Android requires the application to be digitally signed with a certificate. Android uses this certificate to identify the author. Android apps typically use self-signed certificates, in which the app developer holds the certificate’s private key. 23