Overview of Activities

Similar documents
LECTURE NOTES OF APPLICATION ACTIVITIES

UNDERSTANDING ACTIVITIES

Activities. Repo:

States of Activities. Active Pause Stop Inactive

Understand applications and their components. activity service broadcast receiver content provider intent AndroidManifest.xml

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

CMSC436: Fall 2013 Week 3 Lab

Android Activities. Akhilesh Tyagi

CS 528 Mobile and Ubiquitous Computing Lecture 3b: Android Activity Lifecycle and Intents Emmanuel Agu

University of Babylon - College of IT SW Dep. - Android Assist. Lect. Wadhah R. Baiee Activities

Lab 1: Getting Started With Android Programming

CS378 - Mobile Computing. Anatomy of an Android App and the App Lifecycle

Android Fundamentals - Part 1

Minds-on: Android. Session 2

Real-Time Embedded Systems

Embedded Systems Programming - PA8001

CS378 -Mobile Computing. Anatomy of and Android App and the App Lifecycle

Lifecycle Callbacks and Intents

Tablets have larger displays than phones do They can support multiple UI panes / user behaviors at the same time

Activities and Fragments

Lifecycle-Aware Components Live Data ViewModel Room Library

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

EMBEDDED SYSTEMS PROGRAMMING Application Basics

CS 4518 Mobile and Ubiquitous Computing Lecture 5: Rotating Device, Saving Data, Intents and Fragments Emmanuel Agu

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Mobile Programming Lecture 5. Composite Views, Activities, Intents and Filters

Understanding Application

Fragments were added to the Android API in Honeycomb, API 11. The primary classes related to fragments are: android.app.fragment

Vienos veiklos būsena. Theory

UI Fragment.

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Android Services & Local IPC: Overview of Programming Bound Services

CS 370 Android Basics D R. M I C H A E L J. R E A L E F A L L

Have a development environment in 256 or 255 Be familiar with the application lifecycle

Application Fundamentals

Programming Mobile Applications with Android Lab2

Introduction to Android development

Android Services & Local IPC: The Command Processor Pattern (Part 1)

Introduction to Android

Android Application Development

Android Basics. Android UI Architecture. Android UI 1

Services. service: A background task used by an app.

Android. Mobile operating system developed by Google A complete stack. Based on the Linux kernel Open source under the Apache 2 license

CS 4518 Mobile and Ubiquitous Computing Lecture 4: Data-Driven Views, Android Components & Android Activity Lifecycle Emmanuel Agu

Google Maps Troubleshooting

Computer Science E-76 Building Mobile Applications

Android Ecosystem and. Revised v4presenter. What s New

Overview of Java Threads (Part 2)

CS 528 Mobile and Ubiquitous Computing Lecture 3: Android UI, WebView, Android Activity Lifecycle Emmanuel Agu

Mobile Computing Fragments

Android Exam AND-401 Android Application Development Version: 7.0 [ Total Questions: 129 ]

CS 4330/5390: Mobile Application Development Exam 1

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

Overview of Java Threads (Part 3)

Android development. Outline. Android Studio. Setting up Android Studio. 1. Set up Android Studio. Tiberiu Vilcu. 2.

Programming with Android: Intents. Luca Bedogni. Dipartimento di Scienze dell Informazione Università di Bologna

Mobila applikationer och trådlösa nät, HI1033, HT2013

CS378 -Mobile Computing. Services and Broadcast Receivers

MODULE 2: GETTING STARTED WITH ANDROID PROGRAMMING

Mobile User Interfaces

Introduction to Android

Android framework overview Activity lifecycle and states

Produced by. Mobile Application Development. David Drohan Department of Computing & Mathematics Waterford Institute of Technology

MOBILE APPLICATION DEVELOPMENT LECTURE 10 SERVICES IMRAN IHSAN ASSISTANT PROFESSOR

Overview of Java s Support for Polymorphism

INTRODUCTION TO ANDROID

CS 528 Mobile and Ubiquitous Computing Lecture 4a: Fragments, Camera Emmanuel Agu

Mobile Application Development MyRent Settings

Android Programmierung leichtgemacht. Lars Vogel

Infrastructure Middleware (Part 1): Hardware Abstraction Layer (HAL)

COSC 3P97 Mobile Computing

LifeStreet Media Android Publisher SDK Integration Guide

Tongbo Luo Cong Zheng Zhi Xu Xin Ouyang ANTI-PLUGIN: DON T LET YOUR APP PLAY AS AN ANDROID PLUGIN

Programming with Android: System Architecture. Dipartimento di Scienze dell Informazione Università di Bologna

Voice Control SDK. Vuzix M100 Developer SDK. Developer Documentation. Ron DiNapoli Vuzix Corporation Created: July 22, 2015 Last Update: July 22, 2015

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

CS 193A. Activity state and preferences

Fragments and the Maps API

Understanding and Detecting Wake Lock Misuses for Android Applications

COLLEGE OF ENGINEERING, NASHIK-4

Application s Life Cycle

DROIDS ON FIRE. Adrián

Mobila applikationer och trådlösa nät, HI1033, HT2012

Android Basics. - Bhaumik Shukla Android Application STEALTH FLASH

Overview of Frameworks: Part 3

EMBEDDED SYSTEMS PROGRAMMING Android Services

Repairing crashes in Android Apps. Shin Hwei Tan Zhen Dong Xiang Gao Abhik Roychoudhury National University of Singapore

Understanding and Detecting Wake Lock Misuses for Android Applications

Overview of Advanced Java 8 CompletableFuture Features (Part 3)

CHAPTER 3 APPLICATIONS AND ACTIVITIES

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

Orientation & Localization

Introduction to Android Development

Programming with Android: System Architecture. Luca Bedogni. Dipartimento di Scienze dell Informazione Università di Bologna

ABSTRACT I. INTRODUCTION. E. Susmitha, M. Himabindu M.Tech Academic Assistant, IIIT Rk Valley, Rgukt, Andhra Pradesh, India

Android Overview. Most of the material in this sec5on comes from h6p://developer.android.com/guide/

CHAPTER 3 APPLICATIONS AND ACTIVITIES

Login with Amazon. Getting Started Guide for Android apps

Xin Pan. CSCI Fall

Getting started: Installing IDE and SDK. Marco Ronchetti Università degli Studi di Trento

Transcription:

d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA CS 282 Principles of Operating Systems II Systems Programming for Android

Learning Objectives of this Module Understand how an Activity provides a visual interface for user interaction D. C. Schmidt We ll emphasize commonalities & variabilities in our discussion 2

Overview of an Activity An Activity provides a visual interface for user interaction D. C. Schmidt 3

Overview of an Activity An Activity provides a visual interface for user interaction Typically supports one thing a user can do, e.g.: Show a login screen Read an email message Compose a text message View a contact Browse the Internet etc. D. C. Schmidt 4

Overview of an Activity An Activity provides a visual interface for user interaction Typically supports one thing a user can do, e.g.: Show a login screen Read an email message Compose a text message View a contact Browse the Internet etc. Applications can include one or more activities D. C. Schmidt See developer.android.com/training/basics/activity-lifecycle/index.html 5 for more

Tasks A Task is a chain of related Activities Task are not necessarily provided by a single app D. C. Schmidt Activity Activity Activity Activity Task developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html 6

A Task is a chain of related Activities Tasks Task are not necessarily provided by a single app Tasks give the illusion that multiple (often unrelated) Activities were developed as part of the same app D. C. Schmidt developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html 7

Tasks D. C. Schmidt The task s Activity objects are stored on a back stack with the currently running Activity at the top developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html 8

Tasks D. C. Schmidt The task s Activity objects are stored on a back stack with the currently running Activity at the top At runtime Launching an Activity places it on top of the stack Hitting the BACK button pops current activity off the stack developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html 9

Task Stack D. C. Schmidt developer.android.com/guide/topics/fundamentals/tasks-and-back-stack.html 10

Implementing an Activity involves several steps, e.g.: Inherit from Activity class Implementing an Activity public class MapLocation extends Activity { }... 11

Implementing an Activity involves several steps, e.g.: Inherit from Activity class Override selected lifecycle hook methods Implementing an Activity public class MapLocation extends Activity { protected void oncreate (Bundle savedinstancestate); protected void onstart(); protected void onrestart(); protected void onresume(); protected void onpause(); protected void onstop(); protected void ondestroy();... } 12

Implementing an Activity involves several steps, e.g.: Inherit from Activity class Override selected lifecycle hook methods Include Activity in the config file AndroidManifest.xml etc. Implementing an Activity 13 public class MapLocation extends Activity { protected void oncreate (Bundle savedinstancestate); protected void onstart(); protected void onrestart(); protected void onresume(); protected void onpause(); protected void onstop(); protected void ondestroy();... } <activity android:name="course.examples.activity.simplemapexample.maplocation" android:label="map A Location"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name= "android.intent.category.launcher" /> </intent-filter> </activity>

Implementing an Activity involves several steps Android communicates state changes to an Activity by calling its lifecycle hook methods Implementing an Activity 14

Implementing an Activity involves several steps Android communicates state changes to an Activity by calling its lifecycle hook methods Implementing an Activity Commonality: Provides common interface for interacting with user, including operations performed when moving between lifecycle states Variability: Subclasses can override lifecycle hook methods to do necessary work when an Activity changes state 15

Activity Lifecycle States Activity starting Initialization steps startactivity() Starting oncreate(), onstart(), onresume() 16

Activity Lifecycle States Activity starting Initialization steps Activity running Running visible, has focus Paused visible, does not have focus, can be terminated Stopped not visible, does not have focus, can be terminated onrestart(), onstart(), onresume() Starting oncreate(), onstart(), onresume() Stopped startactivity() Running onpause() onstop() onpause() Paused 17

Activity Lifecycle States Activity starting Initialization steps Activity running Running visible, has focus Paused visible, does not have focus, can be terminated Stopped not visible, does not have focus, can be terminated Activity shut down Voluntarily finished or involuntarily killed by the system onrestart(), onstart(), onresume() Starting oncreate(), onstart(), onresume() Stopped ondestroy(), <process killed> startactivity() Running onpause() onstop() Destroyed onpause() Paused <process killed> 18 See developer.android.com/guide/components/activities.html for more info

Managing the Activity Lifecycle Android communicates state changes to application by calling specific lifecycle methods D. C. Schmidt 19

Managing the Activity Lifecycle D. C. Schmidt Android communicates state changes to application by calling specific lifecycle methods The ActivityManager is the system service in Android that communicates these changes developer.android.com/reference/android/app/activitymanager.html 20 has more

Activity Lifecycle Hook Methods The Android runtime calls hook methods on an Activity to control its lifecycle: oncreate() called to initialize an Activity when it is first created 21

Activity Lifecycle Hook Methods The Android runtime calls hook methods on an Activity to control its lifecycle: oncreate() called to initialize an Activity when it is first created onstart() called when Activity is becoming visible to the user 22

Activity Lifecycle Hook Methods The Android runtime calls hook methods on an Activity to control its lifecycle: oncreate() called to initialize an Activity when it is first created onstart() called when Activity is becoming visible to the user onresume() called when user returns to an Activity from another 23

Activity Lifecycle Hook Methods The Android runtime calls hook methods on an Activity to control its lifecycle: oncreate() called to initialize an Activity when it is first created onstart() called when Activity is becoming visible to the user onresume() called when user returns to an Activity from another onpause() called when user leaves an Activity that s still visible in background 24

Activity Lifecycle Hook Methods The Android runtime calls hook methods on an Activity to control its lifecycle: oncreate() called to initialize an Activity when it is first created onstart() called when Activity is becoming visible to the user onresume() called when user returns to an Activity from another onpause() called when user leaves an Activity that s still visible in background onstop() called when user leaves an Activity for another 25

Activity Lifecycle Hook Methods The Android runtime calls hook methods on an Activity to control its lifecycle: oncreate() called to initialize an Activity when it is first created onstart() called when Activity is becoming visible to the user onresume() called when user returns to an Activity from another onpause() called when user leaves an Activity that s still visible in background onstop() called when user leaves an Activity for another ondestroy() called when Activity is being released & needs to clean up its allocated resources See developer.android.com/reference/android/app/activity.html 26 for more info

Overview of Activities Useful Helper Class for Activity Lifecycle Methods public abstract class LifecycleLoggingActivity extends Activity { Inherit from Activity class public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); Log.d(getClass().getSimpleName(), "oncreate()"); if (savedinstancestate == null) Log.d(getClass().getSimpleName(), "activity created anew"); else Log.d(getClass().getSimpleName(), "activity restarted"); } public void onstart() { super.onstart(); Log.d(getClass().getSimpleName(), "onstart()"); }... Automatically log lifecycle hook method calls 27 Note the inversion of control in the Android Activity framework

MapLocation App Example D. C. Schmidt 28