Activities and Fragments

Similar documents
States of Activities. Active Pause Stop Inactive

Minds-on: Android. Session 2

Mobile Application Development Android

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

UI Fragment.

Android Basics. Android UI Architecture. Android UI 1

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

Mobile Computing Fragments

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

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

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

Lifecycle-Aware Components Live Data ViewModel Room Library

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

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

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

Android Ecosystem and. Revised v4presenter. What s New

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

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

Overview of Activities

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

Android Fundamentals - Part 1

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

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

CMSC436: Fall 2013 Week 3 Lab

Lifecycle Callbacks and Intents

Application Fundamentals

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

Intents. 18 December 2018 Lecture Dec 2018 SE 435: Development in the Android Environment 1

EMBEDDED SYSTEMS PROGRAMMING Application Basics

CE881: Mobile & Social Application Programming

UNDERSTANDING ACTIVITIES

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

Activities. Repo:

Understanding Application

Android Activities. Akhilesh Tyagi

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

Mobile User Interfaces

Building User Interface for Android Mobile Applications II

Android Application Development

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

ACTIVITY, FRAGMENT, NAVIGATION. Roberto Beraldi

COLLEGE OF ENGINEERING, NASHIK-4

LECTURE NOTES OF APPLICATION ACTIVITIES

Lecture 2 Android SDK

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

Embedded Systems Programming - PA8001

Fragments and the Maps API

Lab 1: Getting Started With Android Programming

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

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

Vienos veiklos būsena. Theory

Real-Time Embedded Systems

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

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

Programming with Android: Activities and Intents. Dipartimento di Informatica Scienza e Ingegneria Università di Bologna

GUI Design for Android Applications

Mobile Computing. Introduction to Android

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

Fragments. Fragments may only be used as part of an ac5vity and cannot be instan5ated as standalone applica5on elements.

Programming Android UI. J. Serrat Software Design December 2017

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

Hello World. Lesson 1. Android Developer Fundamentals. Android Developer Fundamentals. Layouts, and. NonCommercial

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

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

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

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

CS260 Intro to Java & Android 05.Android UI(Part I)

CS260 Intro to Java & Android 05.Android UI(Part I)

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

Computer Science E-76 Building Mobile Applications

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

Android Application Model I

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

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

COSC 3P97 Mobile Computing

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

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Introduction to Android development

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University. Overview (Review)

Creating a User Interface

CS 4330/5390: Mobile Application Development Exam 1

Programming Mobile Applications with Android Lab2

Understanding Intents and Intent Filters

CHAPTER 4. Fragments ActionBar Menus

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

MODULE 2: GETTING STARTED WITH ANDROID PROGRAMMING

Eventually, you'll be returned to the AVD Manager. From there, you'll see your new device.

CE881: Mobile & Social Application Programming

Mobile Programming Lecture 2. Layouts, Widgets, Toasts, and Event Handling

ListView Containers. Resources. Creating a ListView

Stanislav Rost CSAIL, MIT

Mobile Development Lecture 10: Fragments

EECS 4443 Mobile User Interfaces. More About Layouts. Scott MacKenzie. York University

Android Programming (5 Days)

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

User Interface: Layout. Asst. Prof. Dr. Kanda Runapongsa Saikaew Computer Engineering Khon Kaen University

ConstraintLayouts in Android

MC Android Programming

Introduction to Android

Android Programming Lecture 8: Activities, Odds & Ends, Two New Views 9/28/2011

Transcription:

Activities and Fragments 21 November 2017 Lecture 5 21 Nov 2017 SE 435: Development in the Android Environment 1

Topics for Today Activities UI Design and handlers Fragments Source: developer.android.com 21 Nov 2017 SE 435: Development in the Android Environment 2

What is an Activity? An interactive user element Primary way users interact with apps Can contain elements like Windows Forms (Buttons, Text Boxes, Lists, Menus) Layout is done in separate files and is more like Java Swing 21 Nov 2017 SE 435: Development in the Android Environment 3

Starting an Activity: Intents An activity starts when it gets an intent (from another app/activity) Filter using intent-filter Intent fields: Action: what the recipient should do. Examples: ACTION_CALL, ACTION_DIAL, ACTION_EDIT, ACTION_MAIN, ACTION_BATTERY_LOW, ACTION_VIEW Can define custom Actions Data: Data to operate on (URI). Examples: content://contacts/people/1 For ACTION_CALL, ACTION_DIAL, ACTION_EDIT, ACTION_VIEW, etc. tel:123 Could be ACTION_VIEW, ACTION_DIAL, etc. http://www2.kinneret.ac.il/mjmay Could ACTION_VIEW Can send data empty, but recipient must know what to do 21 Nov 2017 SE 435: Development in the Android Environment 4

Starting an Activity: Intents Type: MIME format of data attached Normally inferred Can be set manually if needed Note: Using a custom action, the MIME type isn t inferred, so set it manually Component: Which component should receive the intent If this is set, no filtering is done, it just receives it Category: More information about the action CATEGORY_LAUNCHER: from the home screen CATEGORY_DEFAULT: normal arrival CATEGORY_BROWSABLE: for browser based intents CATEGORY_OPENABLE: for opening a data picker, use MIME type to restrict what types of resources Extras: Key-value pairs for more information Can include objects 21 Nov 2017 SE 435: Development in the Android Environment 5

Activity Lifetimes Complete lifetime: oncreate(bundle) to ondestroy() Do global setup in oncreate() Kill everything in ondestroy() Ex. thread working in the background Visible lifetime: onstart() to onstop() Activity can be seen Setup resources for the activity to be seen by the user Might go through several iterations Foreground lifetime: onresume() to onpause() Activity completely on top Make these fast and simple since there are many iterations Methods called callbacks Invoked automatically by Android OS 21 Nov 2017 SE 435: Development in the Android Environment 6

Activity Lifetimes OS kills under low memory conditions Pre-Honeycomb, activities could be killed after onpause() Post-Honeycomb, activities can be killed after onstop() onsaveinstancestate(bundle) Save dynamic user data Not always called when stopping (not part of normal lifecycle) Less critical since onstop() is guaranteed post-honeycomb 21 Nov 2017 SE 435: Development in the Android Environment 7

Activity Layouts 21 Nov 2017 SE 435: Development in the Android Environment 8

Activity Layouts Layout can be designed in code or XML: Separate layout from source code, easier updates Multiple layouts, Languages, Screen sizes Elements in XML classes in Java Attributes in XML methods in Java Key classes: View and ViewGroup ViewGroup inherits from View Pattern: Define in XML, retrieve in code and operate When layout or configuration changes (ex. device rotated), activity is killed and restarted 21 Nov 2017 SE 435: Development in the Android Environment 9

Linear Layout: Vertical 21 Nov 2017 SE 435: Development in the Android Environment 10

Linear Layout: Horizontal 21 Nov 2017 SE 435: Development in the Android Environment 11

Other Layout Options 21 Nov 2017 SE 435: Development in the Android Environment 12

View Attributes TextView and Button are Views LinearLayout is a ViewGroup Attributes: id: for reference in code and other Views (RelativeLayout) layout_width, layout_height text Can define handlers for some events in XML Ex: onclick for Button 21 Nov 2017 SE 435: Development in the Android Environment 13

Nesting Layouts Can group layouts and nest them to make complicated arrangements Parent s properties apply to all children 21 Nov 2017 SE 435: Development in the Android Environment 14

Adapter Views Make it easy to show data from a data source Lists Arrays Database cursors Automatically add an a row/block for each element Usually show strings, can override the AdapterView class to customize 21 Nov 2017 SE 435: Development in the Android Environment 15

Fragments Starting with Honeycomb, introduced fragments Backwards compatibility using FragmentActivity class Fragments have their own lifecycle, but are tied to their activity 21 Nov 2017 SE 435: Development in the Android Environment 16

Fragment Lifecycle: Build onattach(activity): Fragment is associated with an activity oncreate(bundle): Initial creation oncreateview(layoutinflator, ViewGroup, Bundle): Creates the View hierarchy onactivitycreated(bundle):containing activity finished its oncreate onviewstaterestored(bundle):all of the state of its Views has been restored onstart(): Visible onresumed(): Is interacting with the user (its activity is resumed) 21 Nov 2017 SE 435: Development in the Android Environment 17

Fragment Lifecycle: Teardown onpause(): Fragment can t interact since it s covered or in the middle of a Fragment operation onstop(): Fragment isn t visible since its activity stopped or in the middle of a Fragment operation ondestroyview(): Fragment should clean up resources from its Views ondestroy(): Final cleanup of state ondetach(): Just before Fragment is removed from its activity 21 Nov 2017 SE 435: Development in the Android Environment 18

Fragments in Layouts Fragments can be put in a layout for inflating Fragment class here is com.example.android.apis.app.fragmentlayout$titlesfragm ent Installer and compiler look for it Can be added and removed from layouts dynamically Code can swap fragments in and out Uses a transaction for each change added to a stack Back pops a transaction off the stack, letting you go back 21 Nov 2017 SE 435: Development in the Android Environment 19

Conclusion Activities UI Design and handlers Fragments 21 Nov 2017 SE 435: Development in the Android Environment 20