Android App Basics Slides from developer.android.com and adopted from Janzen.

Slides:



Advertisements
Similar presentations
Android Application Development A Tutorial Driven Course.
Advertisements

Google Android Introduction to Mobile Computing. Android is part of the build a better phone process Open Handset Alliance produces Android Comprises.
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
What is Android?.
Android architecture overview
Android Platform Overview (1)
Android 02: Activities David Meredith
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Android activities 1 CS300. What makes an app?  Activities: presentation layer  Services: invisible workers  Content Providers: databases  Intents:
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
1 CSCE 4013: Mobile Systems Programming Nilanjan Banerjee Mobile Systems Programming University of Arkansas Fayetteville, AR
Android 101 Application Fundamentals January 29, 2010.
Mobile Application Development
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department Asst.Prof.Dr.Ahmet Ünveren SPRING Computer Engineering Department.
Emerging Platform#4: Android Bina Ramamurthy.  Android is an Operating system.  Android is an emerging platform for mobile devices.  Initially developed.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Mobile Application Development with ANDROID Tejas Lagvankar UMBC 29 April 2009.
Mobile Application Development with ANDROID. Agenda Mobile Application Development (MAD) Intro to Android platform Platform architecture Application building.
About me Yichuan Wang Android Basics Credit goes to Google and UMBC.
Mobile Application Development using Android
Android: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
Android Introduction Based on slides made by
CS5103 Software Engineering Lecture 08 Android Development II.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Copyright© Jeffrey Jongko, Ateneo de Manila University Android.
01. Introduction to Android Prof. Oum Saokosal Master of Engineering in Information Systems, South Korea
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Android for Java Developers Denver Java Users Group Jan 11, Mike
ANDROID 응용 프로그래밍 과정 – 목차 - 안드로이드란 - 안드로이드가 만들어지게 된배경 - 안드로이드의 철학 - 안드로이드 환경설정 ( SDK download, eclipse plug-in 설정, 간단한 프로그램 실행 ) - 안드로이드 동작원리 - 안드로이드 핵심.
10/10/2015 E.R.Edwards 10/10/2015 Staffordshire University School of Computing Introduction to Android Overview of Android System Android Components Component.
Overview of Android Application Development
Android – Fragments L. Grewe.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
ANDROID BY:-AANCHAL MEHTA MNW-880-2K11. Introduction to Android Open software platform for mobile development A complete stack – OS, Middleware, Applications.
Created By. Jainik B Patel Prashant A Goswami Gujarat Vidyapith Computer Department Ahmedabad.
Android App Basics Dr. David Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
1 Android Introduction Platform Overview. 2 What is Android?  Android is a software stack for mobile devices that includes an operating system, middleware.
Android Application Lifecycle and Menus
Lecture 2: Android Concepts
1 Android Workshop Platform Overview. 2 What is Android?  Android is a software stack for mobile devices that includes an operating system, middleware.
By Adam Reimel. Outline Introduction Platform Architecture Future Conclusion.
Android Fundamentals. What is Android Software stack for mobile devices Software stack for mobile devices SDK provides tools and APIs to develop apps.
Introduction to Android Programming
Android Application -Architecture.
Lecture 2: Android Concepts
Android 01: Fundamentals
Open Handset Alliance.
Android Application Development 1 6 May 2018
Mobile Programming Lecture 2
Lecture 2 Zablon Ochomo Android Programming Lecture 2 Zablon Ochomo
ANDROID AN OPEN HANDSET ALLIANCE PROJECT
Activities, Fragments, and Events
MAD.
Activities and Intents
Software Engineering in Mobile Computing
CMPE419 Mobile Application Development
Application Development A Tutorial Driven Course
Activities and Intents
HNDIT2417 Mobile Application Development
Emerging Platform#3 Android & Programming an App
Lecture 2: Android Concepts
CMPE419 Mobile Application Development
Android Development Tools
Presentation transcript:

Android App Basics Slides from developer.android.com and adopted from Janzen

Android Architecture  Android built on Linux 2.6 kernel  What is a kernel?  Provides security, memory management, process management, network stack, and driver model  Abstraction layer between hardware and the software stack 2

Android Architecture  A set of C/C++ libraries exposed to developers through the application framework  System C library - a BSD-derived implementation of the standard C system library (libc), tuned for embedded Linux-based devices  Media Libraries - based on PacketVideo's OpenCORE; the libraries support playback and recording of many popular audio and video formats, as well as static image files, including MPEG4, H.264, MP3, AAC, AMR, JPG, and PNG 3

Android Architecture  A set of C/C++ libraries exposed to developers through the application framework  Surface Manager - manages access to the display subsystem and seamlessly composites 2D and 3D graphic layers from multiple applications  FreeType - bitmap and vector font rendering 4

Android Architecture  A set of C/C++ libraries exposed to developers through the application framework  LibWebCore - a modern web browser engine which powers both the Android browser and an embeddable web view  SGL - the underlying 2D graphics engine 5

Android Architecture  A set of C/C++ libraries exposed to developers through the application framework  3D libraries - an implementation based on OpenGL ES 1.0 APIs; the libraries use either hardware 3D acceleration (where available) or the included, highly optimized 3D software rasterizer  SQLite - a powerful and lightweight relational database engine available to all applications 6

Android Architecture  Runtime libraries provide most of the functionality in the core Java libraries  Each app has a process and an instance of Dalvik VM  Uses Dalvik Executable (.dex) format – low memory footprint  VM is register based runs compiled Java classes  The linux kernel provides Dalvik with needed functionality 7

Android Architecture  Named for Dalvik in Iceland, a fishing village where ancestors of Dan Bornstein lived.  Dalvik is discontinued process virtual machine as of Android version 4.4 (KitKat)  The successor of Dalvik is Android Runtime (ART), which uses the same bytecode and.dex files, aiming at performance I improvements transparent to end users. 8

Android Architecture  The framework allows developers to build cool apps 9

Android Architecture  Set of services and systems  Views to build apps: lists, grids, text boxes, buttons, browser  Content providers enable apps to share data between each other  Resource manager for access to non-code resources such as localized strings, graphics, and layout files  A Notification manager that enables all applications to display custom alerts in the status bar  Activity manager manages lifecycle of apps and provides a common navigation backstack 10

Views  Basic block for a UI component, occupying a rectangle on the screen  It draws and handles events  Widgets – interactive UI components  Buttons, text fields, spinners, date picker, map,etc. 11

Views  ViewGroup – ways to group other views  Layouts – invisible containers holding views and define properties 12

Android Architecture  Core applications ship with android. 13

Resources  Value  Strings, colors, dimensions, arrays (strings, integers, typed), bool, ID,  Drawable – something drawn to the screen  Bitmaps, NinePatch (stretchable) images  PNG is preferred, JPG, and GIF supported  Layout  Layouts define the look of your activity, can specify in XML or with code, XML often easier  Animations  Property – modify object’s property values over time  Tween – rotate, move, stretch, and fade a view  Frame – to display a sequence of images  Color State List – change color based on state  Example: button is pressed, focused, or neither, define color for each  Menu – defines app menu (options, context, submenu, …) that can be inflated  Style – defines the format and look of a UI for view or activity 14

Application Fundamentals  Written in Java, using Android SDK to compile into an Android Package  Each app lives in its own security sandbox (principle of least privilege: only access to what it needs)  Android OS is multi-user with each app a user  Each app gets a user ID  Can be shared between apps (also share same process and VM)  Each process has own VM – runs in isolation  Each app has its own process – started for any component  Can request permission to access device data (SMS, camera…)  Granted at install time 15

Application Components  Intents and Intent Filters  Activities  Services  Content Providers  Broadcast Receivers  App Widgets  Processes and Threads 16

Intents and Intent Filters  Intents and Intent Filters  An Intent is a messaging object you can use to request an action from another app component. Intents (an asynchronous message) are used to start components (except content providers)  Content providers are activated when targeted by a request from a ContentResolver. Call query() on a ContentResolver to query a content Provider  Start Activity - An Activity represents a single screen in an app. You can start a new instance of an Activity by passing an Intent to startActivity().  Start Service - A Service is a component that performs operations in the background without a user interface. You can start a service to perform a one- time operation (such as download a file) by passing an Intent to startService().  Deliver Broadcast - A broadcast is a message that any app can receive. The system delivers various broadcasts for system events, such as when the system boots up or the device starts charging. You can deliver a broadcast to other apps by passing an Intent to sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().  An Intent filter specifies the types of intents that an activity, service, or broadcast receiver can respond to. An intent filter declares the capabilities of its parent component. 17

Activities  Activities  A single screen with a user interface  Example – text message screen, inbox, compose , etc.  They are independent  An app may have more than one  Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time.  Can be started by other applications (if allowed) 18

Activities  Activities  Fragments - A Fragment represents a behavior or a portion of user interface in an Activity. You can combine multiple fragments in a single activity to build a multi-pane UI and reuse a fragment in multiple activities.  Loaders – They make it easy to asynchronously load data in an activity or fragment. They are available to every Activity and Fragment. Monitor the source of their data and deliver new results when the content changes  Tasks and Back Stack - A task is a collection of activities that users interact with when performing a certain job. The activities are arranged in a stack (the "back stack"), in the order in which each activity is opened. When the user presses the Back button, the current activity is popped from the top of the stack (the activity is destroyed) and the previous activity resumes (the previous state of its UI is restored). Activities in the stack are never rearranged, only pushed and popped from the stack 19

Services  Services  Runs in the background for long-running operations or remote processes  Has no user interface  Example – play music, fetch data  An activity can start a service, or bind to a service for interaction. 20

Content Providers  Content Providers  Manages a shared set of application data  Stored in the file system, an SQLite database, on the web, any other persistent location you have access to  Other apps can query or modify data (if allowed)  Example: contact information  Can also be used for private app data 21

Broadcast Receivers  Broadcast Receivers  Responds to system-wide broadcasts  Generally originate from system, i.e. low battery, screen off, picture taken.  Apps can also broadcast, i.e. data ready for use  No user interface but may create a status bar notification  Generally a gateway to other components and light weight  i.e. start a service to perform work based on an event  Any application can start another application’s component  Will start a process for the component’s app, not run in yours  Means no single entry point (i.e main())  You can’t start it, need to have system deliver a message with your intent to start a component  Makes it much easier to add functionality to your app 22

App Widgets  App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates. These views are referred to as Widgets in the user interface, and you can publish one with an App Widget provider. 23

Processes and Threads  When an application component starts and the application does not have any other components running, the Android system starts a new Linux process for the application with a single thread of execution. By default, all components of the same application run in the same process and thread (called the "main" thread).  If an application component starts and there already exists a process for that application (because another component from the application exists), then the component is started within that process and uses the same thread of execution.  You can arrange for different components in your application to run in separate processes, and you can create additional threads for any process. 24

Manifest  Each app has an AndroidManifest.xml file  Declare all the components in this file  In root of app project directory  Identify user permissions required by app (ie internet access, rw contacts,…)  Declare minimum API level required  Declare hardware and software features used or required  i.e camera, bluetooth services, camera, multitouch screen  API libraries needed by app for linking  And more 25

An example Adapted from Janzen 26

A First Example: Advent Devotions 27

UML Class Diagram Generated by Android External Activity 28

Two Activities in Advent Devotions  AdventDevos displays the calendar of dates  Devo displays a single devotion Intent myIntent = new Intent(AdventDevos.this, Devo.class); myIntent.putExtra("ButtonNum", "" + index); startActivity(myIntent); 29

Two Activities in Advent Devotions  AdventDevos displays the calendar of dates  Devo displays a single devotion Bundle extras = getIntent().getExtras(); String value = extras.getString("ButtonNum"); Integer buttonNum = Integer.valueOf(value); 30

Launching an Intent you didn’t write  Devos has button to URL  Browser launched Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(" passage +"&version=NIV")); startActivity(i); 31

Android Activity  “An activity is a single, focused thing that the user can do. Almost all activities interact with the user, so the Activity class takes care of creating a window for you in which you can place your UI with setContentView(View).” Activity.html#ActivityLifecycle 32

Android Manifest.xml <manifest xmlns:android=" package="com.simexusa.adventdevotions" android:versionCode="2" android:versionName="1.0"> <activity android:name=".AdventDevos" Specifies icon for launching app Specifies icon label for launching app Specifies activity to be launched at startup Each upload to PlayStore requires versionCode increment Security permissions requested from user on install SDK version required by app 33

Layouts and Resources  See main.xml and devo.xml  Activity associates with layout xml file using setContentView(R.layout.main); or setContentView(R.layout.devo); in onCreate()  Note TableLayout and TableRow similar to and in html  Note use of dimen (see values/dimens.xml) and color (see values/colors.xml)  Also see strings.xml 34

main.xml <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" <TableLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:text="Nov. 29" android:layout_width="wrap_content" android:layout_height="wrap_content" <Button android:text="Nov. 30" android:layout_width="wrap_content" android:layout_height="wrap_content" <Button android:text="Dec. 1" android:layout_width="wrap_content" android:layout_height="wrap_content" <Button android:text="Dec. 2" android:layout_width="wrap_content" android:layout_height="wrap_content" … 35

devo.xml <LinearLayout xmlns:android=" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center_horizontal" <TextView android:text="Date" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:textStyle="italic" android:typeface="serif" <TextView android:text="Title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" android:textStyle="bold" android:typeface="serif" <Button android:text="Read Scripture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_horizontal" <ScrollView android:layout_height="fill_parent" android:layout_width="fill_parent"> <TextView android:text="Body" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="left" android:typeface="serif" 36

dimens.xml 17sp 20sp 37

colors.xml #AAFFFF99 #FF

strings.xml Hello World, AdventDevos! Advent Devotions 39

Attributes and their Meaning 40

Resources  All Apps have resources (non-code)  Images, audio, animations, menus, styles, colors, layouts…  Can update app characteristics without modifying code  Can have device dependent resources  Different hardware capabilities  Can have user dependent resources  Languages, preferences, etc  Each resource has unique integer ID  Use a qualifier to decide which set of resources to use  Portrait vs landscape  41

Android Application Lifecycle and Menus Adapted from Janzen Except as otherwise noted, the content of this presentation is licensed under the Creative Commons Attribution 2.5 License. 42

Application Lifecycle  Look at Application Fundamentals  Active lifetime  has focus, accepting UI events  onResume to onPause  Visible lifetime  Visible, but does not have focus  onStart to onStop  Full lifetime  onCreate to onDestroy 43

Process Lifecycle  Processes keep around for as long as possible, will kill less important processes  Foreground activity at top of screen user interacting with - most important.  Only killed if out of memory  Visible activity is visible to user but not in foreground, is extremely important  Only killed if required to keep the foreground activity running.  Background activity is not visible (paused) so not critical,  System may kill to reclaim memory for foreground or visible processes.  If user navigates back to activity, onCreate(Bundle) calledonCreate(Bundle)  Empty process is hosting no components.  Killed very quickly as memory becomes low.  Background operations executed in BroadcastReceiver or Service to keep process around. 44

Active Lifetime Example  Campus Maps App  Shows user location on campus map image  45

Active Lifetime Example  Campus Maps  Turn on/off GPS to save battery when UI not in protected void onPause() { super.onPause(); //stop receiving GPS and Orientation data locationManager.removeUpdates(locationListener); protected void onResume() { super.onResume(); //restart receiving GPS and Orientation data locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } 46

Visible Lifetime Example  Campus Maps  Save state as app could get killed after protected void onStop() { super.onStop(); savePreferences(); protected void onStart() { super.onStart(); restoreUIState(); } 47

Visible Lifetime Example  Campus Maps  Save state as app could get killed after onStop() private void savePreferences() { SharedPreferences cmSharedPreferences = getSharedPreferences(CMPREFS,Activity.MODE_PRIVATE); SharedPreferences.Editor editor = cmSharedPreferences.edit(); editor.putBoolean(VIRTUAL_MODE, inVirtualMode); editor.putInt(MAP_INDEX, curMapIndex); editor.commit(); } private void restoreUIState() { SharedPreferences cmSharedPreferences = getSharedPreferences(CMPREFS,Activity.MODE_PRIVATE); inVirtualMode = cmSharedPreferences.getBoolean(VIRTUAL_MODE, true); curMapIndex = cmSharedPreferences.getInt(MAP_INDEX, 0); } 48

UI Elements  View  Control  ViewGroup  Layout  Widget (Compound Control)  Many expected Views  Button, CheckBox, RadioButton  TextView, EditText, ListView  Can be customized by extending and overriding onDraw() 49

XML UI Configuration  Layouts can specify UI elements (provided and custom)  res/layout 50

Menus  Icon Menu (up to 6 icons)  Expanded Menu (from More on Icon Menu)  Submenus 51

Activity lifecycle  Active or running  Top of stack  In foreground of screen  Paused  Visible but lost focus  Stopped  Obscured by another activity  No longer visible, but keeps state  Dead  If paused or stopped can be killed or asked to finish  Must be restarted 52

Activity lifecycle  Called when fist created  Static setup  Create views, bind data, …  Provides Bundle containing activity’s previously frozen state, if there was one  Always followed by onStart() 53

Activity lifecycle  Called after activity has been stopped, prior to it being restarted  Followed by onStart() 54

Activity lifecycle  Called when activity becomes visible to user  Followed by onResume() if activity comes to the foreground or onStop() if becomes hidden 55

Activity lifecycle  Called when activity will start interacting with user  Activity now on top of activity stack, with user input going to it.  Followed by onPause() 56

Activity lifecycle  Called when system about to start resuming a previous activity.  Use to commit unsaved changes to persistent data, stop animations, and anything else consuming CPU  Needs to be very quick since next activity will not resume until done  Followed by OnResume() (activity returns back to front) or onStop() (becomes invisible) 57

Activity lifecycle  Called when the activity is no longer visible  Another activity covering it  New activity started  Existing activity moved to front  This one being destroyed  Followed by onRestart() (activity coming back for interaction) or onDestroy() (going away) 58

Activity lifecycle  Final call before being destroyed  Activity finished (finish() called)  Destroyed by system to save space  Use isFinishing() to figure out which 59

App ideas for Project  Ringer in Vibrate mode based on Calendar notifications  Roll Taker using the Camera  Sync events on multiple different Calendars  Developing useful widgets  Shopping app with nice features (camera, barcode support)  Deal Monitoring app  Weather reporter  International student app (TAMUCC or just CS)  Paint mixer  Islander game, lane based attack, islander theme (tiki)  Humans and Zombies 60