Mobile Application Development BSCS-7 Lecture # 6

Slides:



Advertisements
Similar presentations
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dellInformazione Università di Bologna.
Advertisements

Programming with Android: Activities
Programming with Android: Android for Tablets Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Fragments: Introduction Fragments were introduced in Android 3.0 to support flexible and dynamic UI designs represent portions of an application’s user.
Programming with Android: Activities
Android 02: Activities David Meredith
All About Android Introduction to Android 1. Creating a New App “These aren’t the droids we’re looking for.” Obi-wan Kenobi 1. Bring up Eclipse. 2. Click.
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
Android Fragments.
Android Life Cycle CS328 Dick Steflik. Life Cycle The steps that an application goes through from starting to finishing Slightly different than normal.
More on User Interface Android Applications. Layouts Linear Layout Relative Layout Table Layout Grid View Tab Layout List View.
Programming with Android: Android Fragments Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
Android Fragments A very brief introduction Android Fragments1.
© Keren Kalif Intro to Android Development Written by Keren Kalif, Edited by Liron Blecher Contains slides from Google I/O presentation.
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
Android Info mostly based on Pro Android 3.  User Applications  Java Libraries – most of Java standard edition ◦ Activities/Services ◦ UI/Graphics/View.
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Android Programming-Activity Lecture 4. Activity Inside java folder Public class MainActivity extends ActionBarActivity(Ctrl + Click will give you the.
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Android – Fragments L. Grewe.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
Noname. Conceptual Parts States of Activities Active Pause Stop Inactive.
Activities Димитър Н. Димитров Astea Solutions AD.
Class on Fragments & threads. Fragments fragment is a modular section of an activity, which has its own lifecycle, receives its own input events, and.
CHAPTER 4 Fragments ActionBar Menus. Explore how to build applications that use an ActionBar and Fragments Understand the Fragment lifecycle Learn to.
Services. What is a Service? A Service is not a separate process. A Service is not a thread. A Service itself is actually very simple, providing two main.
Android Fragments. Slide 2 Lecture Overview Getting resources and configuration information Conceptualizing the Back Stack Introduction to fragments.
The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
Guided By: Dr. Mingon Kang
Introduction to android
Android Application -Architecture.
Open Handset Alliance.
Mobile Application Development BSCS-7 Lecture # 2
Activity and Fragment.
Basic Activities and Intents
Android Studio, Android System Basics and Git
Activities, Fragments, and Events
Fragment ?.
Fragments: Introduction
CS499 – Mobile Application Development
Mobile Applications (Android Programming)
Activities and Intents
Android Activities An application can have one or more activities, where Each activity Represents a screen that an app present to its user Extends the.
Anatomy of an Android App and the App Lifecycle
Widgets & Fragments Kalin Kadiev Astea Solutions AD.
Android Mobile Application Development
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
The Android Activity Lifecycle
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
Chapter 9: Fragments.
CIS 470 Mobile App Development
Anatomy of an Android App and the App Lifecycle
Activity Lifecycle Fall 2012 CS2302: Programming Principles.
Android Topics Android Activity Lifecycle and Experiment Toast
Activities and Intents
HNDIT2417 Mobile Application Development
Programming Mobile Applications with Android
CIS 470 Mobile App Development
Activity Lifecycle.
Activities and Intents
Activities and Intents
SE4S701 Mobile Application Development
Mobile Programming Dr. Mohsin Ali Memon.
Activities and Fragments
Android Development Tools
Activities, Fragments, and Intents
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Mobile Application Development BSCS-7 Lecture # 6

Main Building Blocks – Fragments Fragment represents a behavior or a portion of UI in an Activity. It is a kind of sub-activity. Multiple fragments can be combined in a single activity to build a multi-pane UI and reuse a fragment in multiple activities. You can add or remove fragments in an activity while activity is running. An activity can contain any number of fragments. Fragment life cycle is closely related to lifecycle of its host activity which means when activity is paused, all fragments available in activity will also be stopped. Fragments were added to Android API in Honeycomb(3.0) version of Android which API version 11. Earlier we had a limitation because we can show only a single activity on screen at one given point in time. So we were not able to divide device screen and control different parts separately. But with fragment we got more flexibility and removed limitation of having a single activity on screen at a time. Fragments will have their own layout, events and complete lifecycle. You create fragments by extending Fragment class and you can insert a fragment into your activity layout by declaring fragment in activity's layout file, as a <fragment> element.

Main Building Blocks – Fragments

Main Building Blocks – Fragment Lifecycle Phase I: When a fragment gets created, it goes through following states: onAttach() // when a frag is attached to its hosting activity onCreate() //frag is initialized, but no UI onCreateView() //frag sets up and returns its UI. This view is given to hosting activity afterwards. onActivityCreated() // Now frag’s life cycle is depending upon its hosting activity’s life cycle Phase II: When fragment becomes visible, it goes through these states: onStart() //hosting activity is about to become visible onResume() // hosting activity is about to become visible and ready for user interaction Phase III: When fragment goes into background mode, it goes through this states. onPaused() //hosting activity is visible, but another activity is in the foreground and has focus onStop() // When hosting activity is not visible

Main Building Blocks – Fragment Lifecycle Phase IV: When fragment is destroyed, it goes through following states: onPaused() • onStop() onDestroyView() //hosting activity is about to be destroyed any frag that it is hosting also has to be shut down onDestroy() //release frag resources onDetach() //null out references to hosting activity Adding Fragments to Activities Two general ways First, Fragment can be statically added to the activity’s layout file. It is then used in a call to setContentView method. Second, Add it programmatically using FragmentManager

Main Building Blocks – How to use Fragments? This involves number of simple steps to create Fragments. First of all decide how many fragments you want to use in an activity. For example let's we want to use two fragments to handle landscape and portrait modes of the device. Next based on number of fragments, create classes which will extend the Fragment class. Fragment class has above mentioned callback functions. You can override any of the functions based on your requirements. Corresponding to each fragment, you will need to create layout files in XML file. These files will have layout for the defined fragments. Finally modify activity file to define actual logic of replacing fragments based on your requirement. A Useful Trick! Press Ctrl and click on keyword of java in Android Studio. You will get complete definitions of that keyword.