By sending messages into a queue, we can time these messages to exit the cue and call specific functions.



Similar documents
Developing an Android App. CSC207 Fall 2014

ANDROID APP DEVELOPMENT: AN INTRODUCTION CSCI /19/14 HANNAH MILLER

Pedometer Project 1 Mr. Michaud /

Mobile App Tutorial Animation with Custom View Class and Animated Object Bouncing and Frame Based Animation

Android Application Development. Yevheniy Dzezhyts

Developing Android Apps: Part 1

ADITION Android Ad SDK Integration Guide for App Developers

Creating a 2D Game Engine for Android OS. Introduction

Introduction to Android Development. Daniel Rodrigues, Buuna 2014

Presenting Android Development in the CS Curriculum

Create Your Own Android App Tools Using ArcGIS Runtime SDK for Android

Android Quiz App Tutorial

Building Your First App

Tutorial #1. Android Application Development Advanced Hello World App

MAP524/DPS924 MOBILE APP DEVELOPMENT (ANDROID) MIDTERM TEST OCTOBER 2013 STUDENT NAME STUDENT NUMBER

Android App Development. Rameel Sethi

4. The Android System

Mobile Application Frameworks and Services

Android Development Introduction CS314

How to develop your own app

Android Programming Basics

Getting Started: Creating a Simple App

Android Development. Marc Mc Loughlin

Tutorial: Setup for Android Development

Mobile Application Development

Now that we have the Android SDK, Eclipse and Phones all ready to go we can jump into actual Android development.

Android Development Tutorial. Human-Computer Interaction II (COMP 4020) Winter 2013

Mocean Android SDK Developer Guide

How to Create an Android Application using Eclipse on Windows 7

Software Environments of Smartphone Applications

ELET4133: Embedded Systems. Topic 15 Sensors

Getting Started With Android

TUTORIALS AND QUIZ ANDROID APPLICATION SANDEEP REDDY PAKKER. B. Tech in Aurora's Engineering College, 2013 A REPORT

First Certificate in English Online Practice Test Free Sample. How to complete the FCE Online Practice Test Free Sample: Writing

Android For Java Developers. Marko Gargenta Marakana

Intro to Android Development 2. Accessibility Capstone Nov 23, 2010

Android 多 核 心 嵌 入 式 多 媒 體 系 統 設 計 與 實 作

HERE SDK for Android. Developer's Guide. Online Version 2.1

Introduction to Android: Hello, Android! 26 Mar 2010 CMPT166 Dr. Sean Ho Trinity Western University

MMI 2: Mobile Human- Computer Interaction Android

Android Concepts and Programming TUTORIAL 1

How to complete the PET Online Practice Test Free Sample: Listening

TUTORIAL. BUILDING A SIMPLE MAPPING APPLICATION

IELTS ONLINE PRACTICE TEST FREE SAMPLE

Key English Test Online Practice Test Free Sample. How to complete the KET Online Practice Test Free Sample: Reading & Writing

Developer's Cookbook. Building Applications with. The Android. the Android SDK. A Addison-Wesley. James Steele Nelson To

Basics. Bruce Crawford Global Solutions Manager

Big Kev s Little Services Monitor

Android app development course

Android Development Tutorial

Orders.java. ArrayList of Drinks as they are ordered. Functions to calculate statistics on Drinks

Developing NFC Applications on the Android Platform. The Definitive Resource

How To Develop Android On Your Computer Or Tablet Or Phone

5.6.2 Optional Lab: Restore Points in Windows Vista

Saindo da zona de conforto resolvi aprender Android! by Daniel Baccin

Arduino & Android. A How to on interfacing these two devices. Bryant Tram

Login with Amazon Getting Started Guide for Android. Version 2.0

Homeschool Programming, Inc.

Android Programming: Installation, Setup, and Getting Started

B.M. Harwani. Android Programming UNLEASHED. 800 East 96th Street, Indianapolis, Indiana USA

Android Developer Fundamental 1

Chapter 9: Customize! Navigating with Tabs on a Tablet App

Configuring Business Monitor for Event Consumption from WebSphere MQ

Developing Android Applications: Case Study of Course Design

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3 SP02

Android Introduction. Hello Mihail L. Sichitiu 1

Android Application Development: Hands- On. Dr. Jogesh K. Muppala

Android Application Development

Chapter 2 Getting Started

Android Programming. Høgskolen i Telemark Telemark University College. Cuong Nguyen,

Android Development Exercises Version Hands On Exercises for. Android Development. v

OFFICE 365 SELF- CONFIGURATION GUIDE

IELTS ONLINE PRACTICE TEST FREE SAMPLE

Getting Started with Android Programming (5 days) with Android 4.3 Jelly Bean

Beginning Android Programming

IELTS ONLINE PRACTICE TEST FREE SAMPLE

Backend as a Service

Android. Learning Android Marko Gargenta. Tuesday, March 11, 14

Android App Development Lloyd Hasson 2015 CONTENTS. Web-Based Method: Codenvy. Sponsored by. Android App. Development

Getting started with Android and App Engine

How to complete the FCE Online Practice Test Free Sample: Use of English

USING SSL/TLS WITH TERMINAL EMULATION

Tutorial: Android Object API Application Development. SAP Mobile Platform 2.3

Admin. Mobile Software Development Framework: Android Activity, View/ViewGroup, External Resources. Recap: TinyOS. Recap: J2ME Framework

Android Maps Tutorial

Introduction to Android Programming (CS5248 Fall 2015)

Tutorial: Android Object API Application Development. Sybase Unwired Platform 2.2 SP02

EvoDroid: Segmented Evolutionary Testing of Android Apps

Jordan Jozwiak November 13, 2011

How to complete the FCE Online Practice Test Free Sample: Reading

Interfacing PC ChargePayment Server with Focus

Basics of Android Development 1

Lab 1 (Reading Sensors & The Android API) Week 3

Dell OptiPlex XE Watchdog Timer

Android Bootcamp. Elaborado (com adaptações) a partir dos tutoriais:

educ Office Remove & create new Outlook profile

2. Click the download button for your operating system (Windows, Mac, or Linux).

INTRODUCTION TO ANDROID CSCI 4448/5448: OBJECT-ORIENTED ANALYSIS & DESIGN LECTURE 11 02/15/2011

ECE 455/555 Embedded System Design. Android Programming. Wei Gao. Fall

Transcription:

Mobile App Tutorial Deploying a Handler and Runnable for Timed Events Creating a Counter Description: Given that Android Java is event driven, any action or function call within an Activity Class must be called by an event. Up until now, we have used the Button attribute onclick or Listeners attached to SeekBars or EditText boxes to call events. If we need to call a cycle of events, such as displaying a series of images, initiating a countdown, or an animation / game loop, we need a means to have an Activity self call a function repeatedly. We achieve this with a Handler Runnable combination. According to the Android Developer guide: A Handler allows you to send and process Message and Runnable objects associated with a thread's MessageQueue. Each Handler instance is associated with a single thread and that thread's message queue. When you create a new Handler, it is bound to the thread / message queue of the thread that is creating it -- from that point on, it will deliver messages and runnables to that message queue and execute them as they come out of the message queue. By sending messages into a queue, we can time these messages to exit the cue and call specific functions. A Runnable is implemented by the Thread class and works with the Handler to called the function. The Runnable class has a method called run that must be defined when the Runnable is created. The run method will call the function we wish to repeat. The Function / Handler / Runnable cycle can be summarized as follows: 1. External Function Call initiates the Sequence (from oncreate() or a user interaction). 2. Desired Action takes place via a function call. 3. A Check condition is measured within the function call. 4. Depending on Check condition, a Runnable is called with a Delay. 5. Runnable object Calls the desired Function and Sequence again. 6. When Check Condition is False exit the sequence. This Exercise will guide your through creating an App that: 1. Counts Up in whole numbers at one second intervals. 2. Features a Reset Button. In later projects will apply the Handler / Runnable combination to control repeated events, animation loops, and game loops.

Phase 1: Create the App Project Process: 1. Start Eclipse and select new Project -> Android Application Project 2. Fill out the fields with the following: a. Application Name: CountDown b. Project Name: CountDown c. Package Name: com.example.countdown 3. Click Next 4. Click Next at the Configure Project Screen 5. Click Next at the Configure Launcher Screen 6. Click Next at the Create Activity Screen 7. Fill out the following fields in the New Blank Activity Screen a. Activity Name: Countdown b. LayoutName: activity_countdown c. Navigation Type: None 8. Click Finish Phase 2: Android XML User Interface Design Because this is an exercise is only interested in experimenting with Handlers/Runnables, we will use a very basic XML Setup. Objects:

Process: 1. Open the activity_countdown.xml file:

2. Modify the XML Code to setup the texttimer TextView object and the resetbutton Button Object. You will also need to change the layout to Linear Layout. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" tools:context=".countdown" > <TextView android:id="@+id/texttimer" android:layout_width="100dp" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/resetbutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onclick="reset" android:text="reset" /> </LinearLayout>

Phase 3: Write the Java Code for the Countdown.java class. Process: 1. Open the Countdown.java class and add the following fields. (Remember, when an object is not recognized by Eclipse, you can usually hover and import the needed Android or Java class.

2. Modify the oncreate() method to bind the user interface objects to XML and initialize the variables and Handler. Note that on line 37, the count function is called by oncreate() to start the Handler / Runnable Sequence. 3. Write the function for reset. This is called by the restbutton s onclick attribute. 4. Write the count() function to increase the count, display, and call the Runnable.

5. Write the Runnable r to complete the sequence build: 6. Save and run the program on the emulator or device. The App should count up in seconds. (Yes, I know it is not that exciting... More will come later). Classwork Scoring: (Maximum 25 Points) This App is misnamed! It does not count down, it counts up. Please note the scoring for options to fix the App. 1. Complete the Directions and create a working CountDown App as described above: (20 Points) 2. Modify the App to Count Down from 60 and stop at 0. (2 points) 3. Modify the App to Include a Button to Pause and Restart the Count. (3 points)