38
COSC 3P97 Mobile Computing 1.1 COSC 3P97 Mobile Computing

Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

  • Upload
    others

  • View
    5

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.1

COSC 3P97Mobile Computing

Page 2: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.2

COSC 3P97

∙ Prerequisites− COSC 2P13, 3P32

∙ Staff− instructor: Me!− teaching assistant: Steve Tkachuk

∙ Lectures (MCD205)∙ Web− COSC: http://www.cosc.brocku.ca/− COSC 3P97: http://www.cosc.brocku.ca/offerings/cosc3p97/

∙ Email− [email protected]

Page 3: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.3

Course Procedures

∙ Outline∙ Text∙ Software− Android Studio− Let’s see what’s behaving to decide the rest?

∙ Assignments∙ Project− pairs− proposal− platform− presentation− petunias

∙ Presentation∙ Lecture Schedule

Page 4: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.4

Mobile Computing

∙ Software development for mobile equipment− smartphones, tablets

● should these be treated as the same thing?∙ Constraints/Considerations− differ from desktop systems

● think of what the touch/mouse difference alone entails● maybe we should have a quick chat?

− typically● power consumption● screen real estate

⋅ including size, aspect ratio, and pixel density● security model (sandbox)● unexpected interruption of execution● extended “running” time

Page 5: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.5

Marketplace

∙ Platforms− Android, iOS, Windows Phone, Blackberry

∙ Apps− smaller, cheaper, wider distribution− marketplaces run by drivers of platform− differing levels of control/validation− private individuals to large corporations

Page 6: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.6

Android

∙ Driven by Google− Open Handset Alliance (OHA)− multiple H/W vendors− many different configurations

∙ Built around open-source and international standards− Java, XML, LINUX, Open GL ES, SQLite, …− no licensing fees for development− multi-platform development (Windows, OSX and LINUX)

∙ Now a mature platform

Page 7: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.7

Android Platform

∙ Runs on Linux OS− each application runs as a separate user− kernel provides core functions

● e.g. permissions & security, memory management, threading, network stack, H/W access

∙ Dalvik/ART VM− each application runs on its own instance of VM

∙ Access to services/data/personal info− e.g. browser, contacts, phone, …− permissions (granted by user on install)− via managers

● e.g. LocationManager, AudioManager− apps can share data with other apps

Page 8: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity
Page 9: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.9

Development Environment

∙ Typically Android Studio (based on IntelliJ)∙ For instructions see:

http://developer.android.com/sdk/index.html∙ Components− Java JDK (ish)

● also, note that this isn’t mandatory, but Java is typically going to be the easier alternative

− SDK manager● in the lab, you need to change the SDK location!● download/update SDK components● platforms

⋅ at least API 8 (2.2) and a recent one (e.g. API 23/6/M)● after install, check for updates

⋅ be EXTREMELY careful with this!

Page 10: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.10

Testing Environment

∙ Emulator− emulators for various generic Android devices (API levels)− AVD (Android Virtual Device) Manager

● set up emulators for various API levels● we need to look at this carefully

⋅ reduce the available RAM● you’ll likely need to enable/install virtualization support

⋅ I’d suggest avoiding ARM∙ On-device debugging− need USB driver for device− configure device

● select Unknown Sources and USB Debugging

Page 11: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.11

Development Demo

∙ Run Android Studio∙ We’ll create our first real project next week− it has wizards to let you fill in details, and automatically

creates many files for you∙ Create an emulator− AVD Manager− ideally, you’ll create only one and reuse it for the whole term

∙ Run on emulator

Page 12: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.12

Project Files

∙ Generated directories− src/main

● project code− source/main/java

● java code− res

● resources● /layout

⋅ GUI⋅ GUI editor

− AndroidManifest● project description

Page 13: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.13

Logging

∙ We’ll look at logging later, but it’s a powerful tool− it can log multiple types of messages, which can then be

separated or filtered as necessary− this includes tracking multiple types of logs, potentially from

different sources− think of it as an improved System.err

∙ Import android.util (for Log class)∙ Levels− errors, warnings, information, debug, verbose

Page 14: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.14

Debugging

∙ Debug− available as perspective in Eclipse− breakpoints− stepping through code− examining variables

∙ DDMS (Monitor)− perspective− devices− threads− profiling− screenshots

Page 15: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.15

Distribution

∙ Generate an Application Package (.apk)− generates .dex code (Dalvik Executable)− includes manifest− has an unique ID (unchanged through releases)− signed with a certificate− since introduction of ART:

● https://source.android.com/devices/tech/dalvik/∙ Distributed− Android Marketplace

● controlled by Google● register as Android developer

− directly from developer● you may need to enable ‘Outside Sources’ to side-load

Page 16: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.16

AndroidApplication Basics

Page 17: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.17

Foundational Classes

∙ Context− android.content.Context− application-wide configuration and data− instantiated as an Application object

∙ Activity− android.app.Activity− single task in an application− usually associated with a screen (UI)− subclass of Context

∙ Fragment− android.app.Fragment− new in Android 3.0 (11)− single function (UI) within a task− can be shared between activities

Page 18: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.18

∙ Intent− android.app.Intent− encapsulates an asynchronous message to/from another

activity− for inter-task communication/coordination

∙ Service− android.app.Service− task without user interaction− time-consuming or periodic tasks− background− subclass of Context

Page 19: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.19

Context

∙ Accessing (in Context)− Context context = getApplicationContext();

∙ Access to− resources

● getResources● res directory● R.java

− preferences● simple shared application data (configuration, state)● getSharedPreferences

− also: private files, assets, services, database, permissions

Page 20: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.20

Activity

∙ Typically one per task that has UI∙ Handles interaction with one screen∙ Must be defined in the manifest∙ e.g. simple game− splash screen− main menu− high scores, play, help

Page 21: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity
Page 22: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.22

Processes

∙ Multi-processing− concurrent applications− application can multi-process− interrupts (e.g. phone call)− foreground/background

∙ Activity is unit for multi-processing∙ Activity stack − though this is a slightly odd ‘stack’

∙ Application must manage resources and pause and resume seamlessly

Page 23: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity
Page 24: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.24

Activity Lifecycle

∙ States∙ Callbacks− Activity methods to be overridden

● should call superclass method− onCreate(Bundle savedInstanceState)

● first started or restarted after killed● bundle may have state information if killed● initial setup including setContentView

− onResume()● before becoming active● obtain resources needed to run● start resource hungry activities (e.g. audio play)

Page 25: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity
Page 26: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.26

− onPause()● about to move to background● save resources loaded in resume● stop resource hungry activities● cleanup so less likely to be killed

− onStop() & onDestroy()● not necessarily called

− example

Page 27: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.27

Fragment

∙ New in API 11∙ Subdividing UI processing− compartmentalizing UI processing− common UI between activities

∙ e.g. multi-function (drill down) in music player

Page 28: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity
Page 29: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.29

Intent

∙ Transitioning between activities− permanent

● e.g. splash screen to main menu● new activity takes over, previous discarded● use startActivity and finish

− temporary● e.g. main menu to functions● expect to return (back)● new activity pushed on top of previous● use startActivityForResult and onActivityResult

Page 30: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.30

∙ Intent object− used to determine which activity to start− used to pass data to activity

∙ Starting activity− can start activity by name (class)− can start activity by intent filter

● activities register intents they handle∙ Passing data− intent has associated bundle (called Extras)− name/value pairs− putExtra and getExtras

Page 31: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.31

Manifest

∙ XML file that defines the application∙ Part of the package (.apk) that is generated from your project for

distribution∙ Describes properties for installation− name & icon− system requirements− permissions− registering components (activities, services etc.)

∙ Manifests are one of the biggest compatibility nuisances when upgrading Studio and APIs

Page 32: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity
Page 33: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.33

Identity

∙ Package name∙ Version− code vs name

∙ App name∙ Icon

Page 34: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.34

System Requirements

∙ SDK version− min

● backwards compatibility− target

● most up-to-date− max

● only in special cases∙ Versions− each API level affords new features you can use, but also

shrinks the potential install base

Page 35: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity
Page 36: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.36

Platform Requirements

∙ Input− uses-configuration− keyboards, navigation devices, touch screen settings

∙ Features− uses-feature− optional device features/hardware

∙ Screen sizes and density− supports-screens− small/normal/large

∙ Note that resolution, by itself, isn’t terribly descriptive, let alone helpful

Page 37: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.37

Activities

∙ Activities must be defined in the manifest to be used∙ Must be within the package declared in the manifest− dot notation or full pathname

∙ Primary entry point defined with an intent filter− action: MAIN− category: LAUNCHER

∙ Other intent filters can be specified to indicate that an activity, service or receiver can respond to implicit intents

Page 38: Mobile Computing COSC 3P97 - Brock Universityefoxwell/3P97/Week01.pdf · ∙ Application must manage resources and pause and resume seamlessly. COSC 3P97 Mobile Computing 1.24 Activity

COSC 3P97

Mobile Computing 1.38

Permissions

∙ Access to shared resources− e.g. contacts database, hardware such as camera

∙ Must be requested− uses-permission− upon install user must grant permission

∙ May not be enforced by all devices but request anyway∙ Activities can also define and enforce their own permissions− when used by other applications