CE881: Mobile & Social Application Programming

Similar documents
CE881: Mobile & Social Application Programming

Activities and Fragments

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

Android Fundamentals - Part 1

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

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

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

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

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

Lecture 2 Android SDK

COLLEGE OF ENGINEERING, NASHIK-4

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

(Refer Slide Time: 0:48)

CS378 -Mobile Computing. More UI -Part 2

Fragments and the Maps API

Multiple devices. Use wrap_content and match_parent Use RelativeLayout/ConstraintLayout Use configuration qualifiers

Android Programming Lecture 2 9/7/2011

Lab 1: Getting Started With Android Programming

CS 4330/5390: Mobile Application Development Exam 1

LECTURE NOTES OF APPLICATION ACTIVITIES

UI Fragment.

UNDERSTANDING ACTIVITIES

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

Real-Time Embedded Systems

CMSC436: Fall 2013 Week 3 Lab

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

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

MARS AREA SCHOOL DISTRICT Curriculum TECHNOLOGY EDUCATION

XML Tutorial. NOTE: This course is for basic concepts of XML in line with our existing Android Studio project.

Android. Lesson 1. Introduction. Android Developer Fundamentals. Android Developer Fundamentals. to Android 1

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

Android Basics. Android UI Architecture. Android UI 1

Android App Development. Ahmad Tayeb

Mobile Development Lecture 10: Fragments

GUI Design for Android Applications

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

INTRODUCTION TO ANDROID

Lab 1 - Setting up the User s Profile UI

CS371m - Mobile Computing. More UI Navigation, Fragments, and App / Action Bars

Android Essentials with Java

Mobile Computing Professor Pushpedra Singh Indraprasth Institute of Information Technology Delhi Andriod Development Lecture 09

Syllabus- Java + Android. Java Fundamentals

Android Ecosystem and. Revised v4presenter. What s New

COSC 3P97 Mobile Computing

CS371m - Mobile Computing. More UI Action Bar, Navigation, and Fragments

ATC Android Application Development

Minds-on: Android. Session 2

Configuring the Android Manifest File

Introduction to Android

CS378 -Mobile Computing. What's Next?

Android" Application Development SAMS. Sams Teach Yourself. Shane Conder. Lauren Darcey. Second Edition

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

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

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

Android System Architecture. Android Application Fundamentals. Applications in Android. Apps in the Android OS. Program Model 8/31/2015

Embedded Systems Programming - PA8001

COMP4521 EMBEDDED SYSTEMS SOFTWARE

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

EMBEDDED SYSTEMS PROGRAMMING UI and Android

Android Online Training

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

Lifecycle Callbacks and Intents

Login with Amazon. Getting Started Guide for Android apps

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

ANDROID APPLICATION DEVELOPMENT COURSE Training Program

Introduction To JAVA Programming Language

Overview of Activities

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

ANDROID SERVICES, BROADCAST RECEIVER, APPLICATION RESOURCES AND PROCESS

Introduction to Android development

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

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

Orientation & Localization

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

android application development CONTENTS 1.1 INTRODUCTION TO O ANDROID OPERATING SYSTEM... TURES Understanding the Android Software Stack...

Beginning Android Tablet

Lab 3: Using Worklight Server and Environment Optimization Lab Exercise

Introduction to Mobile Application Development Using Android Week Four Video Lectures

CS 235AM, Mobile Application Development: Android Spring 2016

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

Android App Development. Muhammad Sharjeel COMSATS Institute of Information Technology, Lahore

CMSC436: Fall 2013 Week 4 Lab

Android Application Development

MC Android Programming

Fig. 2.2 New Android Application dialog. 2.3 Creating an App 41

(Refer Slide Time: 1:12)

EMBEDDED SYSTEMS PROGRAMMING Application Basics

Operating Systems 2 nd semester 2016/2017. Chapter 4: Threads

SEVEN ADVANCED ACADEMY

Developing Android Applications Introduction to Software Engineering Fall Updated 1st November 2015

Introduction to Android

Spring Lecture 5 Lecturer: Omid Jafarinezhad

Getting Started with Android Development Zebra Android Link-OS SDK Android Studio

Fragments. Lecture 10

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

ANDROID. Curriculum LOCATION CONTACT US SCHEDULE. TurnToTech 40 Rector St. 10th Floor New York, NY

Lab 3. Accessing GSM Functions on an Android Smartphone

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

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

Contextual Android Education

Transcription:

CE881: Mobile & Social Application Programming, s, s and s Jialin Liu Senior Research Officer Univerisity of Essex 6 Feb 2017

Recall of lecture 3 and lab 3 :) Please download Kahoot or open a bowser and go to https://kahoot.it/ Game PIN : Let s start!

Today s application Recall of lecture 3 and lab 3 We ve seen Every Day Travel information (transport) BlackBox game Kahoot education Today s app is not a single one, but a group of apps : social network Facebook Twitter Instagram Snapchat"... How to make money with these applications?

Service : what? Recall of lecture 3 and lab 3 App components Stay in the background Provide a long-running support for the app Example : notification

Service : why? Recall of lecture 3 and lab 3 Runs in the background as normal even if the app is minimised Not on it s own thread (unless explicitly programmed to do so) Exposes non-visual functionality to third parties Allows proper interprocess communication (if needed)

Service : how? Recall of lecture 3 and lab 3 Step1 : Edit the AndroidManifest.xml (don t forget...)

Service life cycle Recall of lecture 3 and lab 3 1 1. https ://developer.android.com/guide/components/services.html

Two types of services Default Service : Does not handle threads, must be done manually Intent Service : Handles requests one by one

More on services Recall of lecture 3 and lab 3 Asynchronous - When the service is finished, call some global variable How about remote calls - or long running service? To be used if you require that the service is accessed by third party apps Provide a messaging interface

Example 1 : Default Service (1/2) How to communicate with a remote service

Example 1 : Default Service (2/2) How to communicate with a remote service

Example 2 : Intent Service (1/2) How to set up a notification

Example 2 : Intent Service (2/2) How to set up a notification Did I forget something? :)

Recall of lecture 3 and lab 3 3 types of menus : Options Will pop up when the menu button is pressed on an app The location of the button depends on the device : on modern nexus devices it appears as a column of dots in the ActionBar Popup Appears when an item within a view is clicked, where the item handles the relevant event Context Appears on items that handle a long-click event s can be declared in XML or in Java

examples Recall of lecture 3 and lab 3 Options, Popup, Context (left->right) Figure Examples from developer.android.com.

: all about selection A menu presents one or more items for a user to select When the item is selected an action should be taken s are added to parent views Write a method to handle the appropriate event It is common for the same method to handle many menu item selections Then use a switch statement to detect which item was selected

Creating a in XML Question : Difference between android:id="@+id/action_settings" and android:id="@id/action_settings"

Then loading it in Java Override the oncreateoptions method Use a Inflater to build the menu Note : menu_main matches the name of the xml file (menu_main.xml) in the folder res/menu/

Creating a in Java Override the oncreateoptions method Add the menu item and assign the return value to a reference variable of type Item Call methods of the Item object to modify its appearance or where it appears Figure In addition to adding a menu item labelled Test we also add an Icon to it

Frustrating Differences The exact appearance of a menu differs with version of Android OS (or variations in UI added by manufacturer) Another reason to test the app on different Android OS, different devices before publishing

Adding Custom Icons Normal practice is to either : Use Android Platform Icons Add your own in the drawable folder Ideally there should be separate versions for each resolution The IDE may do this for you Somehow you need to do it automatically for your sanity But it s also possible to draw your own at Runtime?

Dynamic Icon Creation When setting up the menu icon : seticon() can take adrawable (Drawable is an Abstract Class) So do this : class MyIcon extends Drawable {... Then implement the draw(canvas canvas) method Doing this felt a bit off piste - it might be useful - and was an interesting exercise, but use with some caution

s Recall of lecture 3 and lab 3 s can be built very easily using the Alert builder You can set it as a message or a question to answer (choose choice or insert text) Set Ok and/or Cancel button

s Recall of lecture 3 and lab 3 The code assumes this is being called from a method of an Activity (note the this object being passed to the Alert.Builder(this) constructor The rest of the code : Sets the title and message strings Sets handlers for the onclick events for each button Shows the

Custom s Recall of lecture 3 and lab 3 Main idea : Your custom class will extend Use the Alert.Builder as before Override the oncreate method within the subclass Then create a new instance of your class and call its show method to show it See https://developer.android.com/guide/topics/ui/dialogs.html for examples.

Specifying a Custom Layout Main idea : Within the builder we can call setview to set a custom view Can use Views specified in XML or created dynamically in Java This is equivalent to the setcontentview we ve used in the oncreate method of an Activity The relevant line on the next slide (copied from the Android developer guide) is below Note that the code looks more complex than necessary due to method call chaining

Sample code Recall of lecture 3 and lab 3

Recall of lecture 3 and lab 3 s offer a powerful way to compose Apps in a highly modular way Choice of Layout can easily depend on screen size Each has it s own lifecycle, tied to its parent activity s cycle Composing an Activity from several fragments offers flexibility The overhead is additional coding

s and Android API Versions s have native support from API 11 (Honeycomb, 3.0) onwards If compatibility with earlier versions is required then the Android Support Library must be used This also leads to some differences in the code s always belong to an Activity i.e. an Activity hosts a From API 11 onwards, any Activity can host a With earlier APIs and the Support Library, a Activity is needed (or a sub-class of this)

Example Recall of lecture 3 and lab 3 Question : in each case how would you achieve the following without using s??see http://developer.android.com/training/basics/ fragments/fragment-ui.html for examples

Defining GUIs Like other layouts, can be done in XML or in Java code XML trick : Define two layouts, one for small screen, one for tablet (large screen) The one for the tablet must be in a directory with the large qualifier e.g. two layouts could be : res/layout/news_articles.xml res/layout-large/news_articles.xml When the layout is inflated the correct one will be chosen Following shows Basics example on Nexus One and Nexus 7 emulators

Basics Example Note the different layouts

s in Java Code When s are added to XML layouts they cannot be removed in code Alternative : s can be added or removed with the appropriate Java This enables dynamic construction of GUIs BUT NOTE : all additions and removals of s MUST be done within a Transaction Question : why is this so?

Implementing s Main idea : Similar to defining an Activity Except main override for Activity is oncreate() For use : oncreateview() // check the savedinstancestate // inflate the layout onstart() // can now update view components since layout is ready for use // perform any initialisation and restoration of state

Managing s The host activity is responsible for : Creating, adding and removing fragments Note : To be visible each must be added to a View Within the code, Save any state by overriding onpause() or onsavedinstancestate()

Programming with s Note : communication between sibling fragments is not allowed* Instead communicate via parent activity Also, see examples here : http://developer.android.com/training/basics/ fragments/fragment-ui.html http://developer.android.com/training/animation/ cardflip.html Question : There is nothing to stop you trying this, but why do you think it is not allowed" Question : Do you need more than one activities in your app? Why not just stick to fragments?

XML s - loading

Programmatically Recall of lecture 3 and lab 3

Recall of lecture 3 and lab 3 With these s and s you can build sophisticated custom-designed User Interfaces for your apps Practice these ideas in the lab Use fragments s are recommended for building apps in a scalable and flexible way Especially good for coping with different screen sizes They are reusable modules that always belong to a parent (host) Activity But are responsible for managing some lifecycle callbacks to initialise, save, and restore their state

Progress test Recall of lecture 3 and lab 3 10-11am, 17 Feb (week 20) Under exam conditions 20 Questions 40 mins Sample progress test? You ve seen the sample test every week (Kahoot)

Course outline/structure was based on Spyros Samothrakis s 2015 Course Course outline/structure was based on Simon Lucas s 2014 Course