Lifecycle Callbacks and Intents

Similar documents
UNDERSTANDING ACTIVITIES

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

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

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

Lab 1: Getting Started With Android Programming

States of Activities. Active Pause Stop Inactive

CMSC436: Fall 2013 Week 3 Lab

Overview of Activities

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

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

Introduction to Android development

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

Activities and Fragments

Lifecycle-Aware Components Live Data ViewModel Room Library

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Programming Mobile Applications with Android Lab2

Android for Ubiquitous Computing Researchers. Andrew Rice University of Cambridge 17-Sep-2011

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (Part 1-2) Hello-Goodbye App Tutorial

Android Fundamentals - Part 1

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

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

Computer Science E-76 Building Mobile Applications

Activities. Repo:

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

Google Maps Troubleshooting

CPET 565 Mobile Computing Systems CPET/ITC 499 Mobile Computing. Lab & Demo 2 (1 &2 of 3) Hello-Goodbye App Tutorial

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

Minds-on: Android. Session 2

Android Basics. Android UI Architecture. Android UI 1

INTRODUCTION TO ANDROID

Real-Time Embedded Systems

Android Ecosystem and. Revised v4presenter. What s New

LECTURE NOTES OF APPLICATION ACTIVITIES

CS 4330/5390: Mobile Application Development Exam 1

Mobile Computing Fragments

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

Vienos veiklos būsena. Theory

Assignment 1: Port & Starboard

Orientation & Localization

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

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

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

PILOT FM Radio SDK AUGUST 31, 2016

Embedded Systems Programming - PA8001

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

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

Introduction to Android

Comp 595MC/L: Mobile Computing CSUN Computer Science Department Fall 2013 Midterm

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

Android Programming Lecture 2 9/7/2011

UI Fragment.

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

MVC Apps Basic Widget Lifecycle Logging Debugging Dialogs

Create new Android project in Android Studio Add Button and TextView to layout Learn how to use buttons to call methods. Modify strings.

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

Android Activities. Akhilesh Tyagi

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

Understanding Application

COLLEGE OF ENGINEERING, NASHIK-4

Android Programmierung leichtgemacht. Lars Vogel

Basic Android Setup for Machine Vision Fall 2015

Android Application Development

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

Agenda. Overview of Xamarin and Xamarin.Android Xamarin.Android fundamentals Creating a detail screen

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

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

MODULE 2: GETTING STARTED WITH ANDROID PROGRAMMING

Programming with Android: Android for Tablets. Dipartimento di Scienze dell Informazione Università di Bologna

University of Stirling Computing Science Telecommunications Systems and Services CSCU9YH: Android Practical 1 Hello World

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

ANDROID MOCK TEST ANDROID MOCK TEST IV

Building MyFirstApp Android Application Step by Step. Sang Shin Learn with Passion!

Hello World. Lesson 1. Create your first Android. Android Developer Fundamentals. Android Developer Fundamentals

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

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

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,

Xin Pan. CSCI Fall

Fragments and the Maps API

EMDK for Android Workshops Prashanth Kadur

(Refer Slide Time: 1:12)

Understanding and Detecting Wake Lock Misuses for Android Applications

Exercise 1: First Android App

Mobile User Interfaces

Steps to Set Up the Environment of Xamarin in Visual

Our First Android Application

Diploma in Android Programming (DAP)

Introduction to Android

CE881: Mobile & Social Application Programming

Understanding and Detecting Wake Lock Misuses for Android Applications

Mobile Programming Lecture 1. Getting Started

Lecture 2 Android SDK

Upon completion of the second part of the lab the students will have:

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

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Activity Logging Lecture 16

1. Implementation of Inheritance with objects, methods. 2. Implementing Interface in a simple java class. 3. To create java class with polymorphism

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

CS378 -Mobile Computing. More UI -Part 2

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

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

Transcription:

SE 435: Development in the Android Environment Recitations 2 3 Semester 1 5779 4 Dec - 11 Dec 2018 Lifecycle Callbacks and Intents In this recitation we ll prepare a mockup tool which demonstrates the lifecycle of an Activity and shows how to use a very simple kind of Intent - an explicit intent. 1 Activity Lifecycle Callbacks As discussed in class, there are seven main callback functions in the lifecycle of an Activity: 1. oncreate 2. onstart 3. onresume 4. onpause 5. onrestart 6. onstop 7. ondestroy To better understand how the lifecycle callbacks are run and in what order, we ll make a simple app which prints out a notice whenever a lifecycle callback function is invoked. We ll perform the following steps: 1. Create an app with minimum SDK level 15 (to prevent bugs with the ActionBar). We ll override the API callbacks listed above (oncreate, onstart, onresume, onpause, onrestart, onstop, ondestroy) and print out a line in the log whenever they are called. For simplicity, we ll start with a simple logging function: private void logline(string line) { Log.i(LOG TAG, line); } This logging function prints a line which we can see in LogCat each time we call it. We ll just provide an appropriate line in each callback function. To make this work, we need to also define a variable called LOG TAG in the class: private final String LOG TAG = "Activity Lifecycle"; 2. We ll make the logging more interesting by adding a TextView on the main activity screen to show the log as well. After we add the TextView (called tveventlog), we can modify the logging function to be as follows: private void logline(string line) { Calendar c = Calendar.getInstance(); TextView tv = (TextView)findViewById(R.id.tvEventLog); tv.settext(c.get(calendar.hour_of_day) + ":" + c.get(calendar.minute) + ":" + c.get(calendar.second) + c.get(calendar.millisecond) + " " + line + "\n" + tv.gettext());; Log.i(LOG_TAG, line); } This function also prepends the log line and time for the event. 1

2 Adding Strings Translations Android coding conventions call for the storage of static strings in a file called strings.xml in the values folder of the app, rather than hard coded into the program. This has a number of advantages, primarily for portability. In this stage of the recitation we ll modify strings.xml file to contain strings for each line we want to log and replace all string literals in the code with references to the strings. To make the app more portable, we ll also create Hebrew versions of strings.xml which we will store in the values-iw folder. We can then change the language of the device and see that all strings are replaced consistently with their Hebrew translation. We can then see the Hebrew strings by changing the language of the device or emulator. Translating strings can be done more easily using the Translation Editor window in Android Studio as shown below. The editor allows you to prepare multiple translations for each string. In the figure below, there is Hebrew and Russian for each English string. 3 Adding Another Activity In the final part of the recitation, we ll add a second activity to the app (call it SecondActivity). The second activity will have a two Buttons and two TextViews. A screen shot is shown below: 2

The top button causes the activity to generate two random numbers which are displayed above. The bottom button causes the activity to run its finish function which closes it. We ll also add a Button to the top activity which lets us call the second activity. Clicking on the Button causes an explicit Intent to be created and sent, leading to the creation of the second activity. A final screen shot of the top activity is shown below: 3

Screen shots of the activities in Hebrew are shown below. Note that the text is shown in correct right to left, but the layout is a bit messed up. We could create separate layouts for the RTL languages to make sure that the Buttons and TextViews are shown in more logical locations. 4

5