Android Fragments.

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.
Activity Applications were originally built on the Activity class. AD * : “An activity is a single, focused thing that the user can do. Almost all activities.
Fragments: Introduction Fragments were introduced in Android 3.0 to support flexible and dynamic UI designs represent portions of an application’s user.
The Web Warrior Guide to Web Design Technologies
Programming with Android: Activities
Android 02: Activities David Meredith
The Android Activity Lifecycle. Slide 2 Introduction Working with the Android logging system Rotation and multiple layouts Understanding the Android activity.
The Activity Class 1.  One application component type  Provides a visual interface for a single screen  Typically supports one thing a user can do,
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.
Chien-Chung Shen Manifest and Activity Chien-Chung Shen
Android: versions Note that: Honeycomb (Android v3.0) A tablet-only release Jelly Bean (Android v4.1) Released on July 09, 2012.
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 Mobile computing for the rest of us.* *Prepare to be sued by Apple.
Tip Calculator App Building an Android App with Java © by Pearson Education, Inc. All Rights Reserved.
This work is licensed under the Creative Commons Attribution 4.0 International License. To view a copy of this license, visit
Mobile Programming Lecture 6
Activities and Intents. Activities Activity is a window that contains the user interface of your application,typically an application has one or more.
Creating Dialog (ABAP Dynpro) Programs. Slide 2 Introduction All of the ERP systems operate similarly with regard to transactional integrity They all.
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Understand applications and their components activity service broadcast receiver content provider intent AndroidManifest.xml.
Android – Fragments L. Grewe.
5-1 More UI CSNB544 Mobile Application Development Thanks to Utexas Austin.
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.
More UI Action Bar, Navigation, and Fragments
Fragment Android Club Agenda Fragment Static fragment Dynamic fragment ViewPager.
CS378 - Mobile Computing More UI. UI Review Containers – more formally ViewGroups – store widgets and other containers – examples: LinearLayout, RelativeLayout,
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.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
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.
ANDROID DIALOGS. Slide 2 Dialogs (Introduction) The Dialog class is the base class for all dialogs A dialog is a small window that prompts the user to.
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
Open Handset Alliance.
Activity and Fragment.
Activities, Fragments, and Events
Fragment ?.
Fragments: Introduction
Android 3: Fragments: API Guide
CS499 – Mobile Application Development
Mobile Application Development BSCS-7 Lecture # 6
Android 16: Fragments: Tutorial
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.
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.
Android 15: Fragments: API Guide
The Android Activity Lifecycle
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
CIS 470 Mobile App Development
Chapter 9: Fragments.
Activity Lifecycle Fall 2012 CS2302: Programming Principles.
Activities and Intents
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
SE4S701 Mobile Application Development
Mobile Programming Dr. Mohsin Ali Memon.
Activities and Fragments
Activities, Fragments, and Intents
Android Sensor Programming
Presentation transcript:

Android Fragments

Lecture Overview Another way to get configuration information Conceptualizing the Back Stack Introduction to fragments

Configuration Information android.content.Configuration contains configuration information about your device Screen size: screenHeightDP, screenWidthDP Orientation contained in the orientation property: ORIENTATION_LANDSCAPE, ORIENTATION_PORTRAIT

Configuration Information The following statement gets the configuration

The Back Stack (Introduction) An application is made up of multiple activities And as you know one activity can start another activity, which can, in turn start another activity Activities are connected together as a task Whether in the same or different applications This sequence of activities in a task is called the back stack

The Back Stack (Illustration)

Fragments (Introduction) A fragment is a behavior or part of a user interface that can be placed in an activity Use it to create a multi-pane UI Reuse the same fragment in multiple activities Think of a fragment as a modular section of an activity which: Has its own lifecycle Receives its own input events

Fragments (Characteristics) Fragments are always embedded in an activity Fragments are controller objects An activity’s view contains visual space where the fragment’s view will be inserted An activity can have several fragments Fragments were introduced at API level 11 along with the first tables There is a support library for older versions

Fragments (Illustration 1) Activity with two fragments (tablet)

Fragments (Illustration 2) Activity with two fragments (handset)

The Fragment Lifecycle It operates similar to the activity lifecycle When an activity is paused, all fragments in it are paused Fragments can be manipulated independently of the parent activity

The Fragment Lifecycle

Overriding Fragment Methods (Create) To create a fragment you create a subclass of Fragment (looks like an activity) You almost always implement the following methods The system calls onAttach(), when the fragment is associated with an activity The system calls onCreate() when creating the fragment

Overriding Fragment Methods (Create) The systems calls onCreateView() when the fragment is rendered the first time onActivtyCreated() tells the fragment that the activity has completed it’s call to Activity.OnCreate() onStart() makes the fragment visible (same as activity) onResume() starts user interaction (same as activity)

Overriding Fragment Methods (Destroy) The system calls onPause() when the user is leaving the fragment onStop() is called when the fragment is no longer visible onDestroyView() allows the fragment to clean up resources associated with the currentview onDestroy() is called to do final cleanup onDetach() is called when the fragment is disassociated with the activity

Hosting Fragments There are two ways to host fragments: In the activity’s layout (static definition) Inflexible because the fragment cannot be swapped out during the activity lifetime In the activity’s code (dynamic definition) Better because you and dynamically add and remove different fragments More complicated

Hosting Fragments (Static Definition)

Hosting Fragments (Layout) You connect the layout using the same techniques that you have seen

Hosting Fragments (Code) Add a fragment to an existing ViewGroup The FragmentManager is responsible for managing fragments and adding views to the activity’s view hierarchy It manages A list of fragments And a back stack of fragment transactions

FragmentManager (Illustration)

Getting the Fragment Manager Use getFragmentManager() to get the current fragment manager If you need compatibility with older versions, use getSupportFragmentManager() FragmentManager fragmentManager = getFragmentManager()

Managing Fragments (Introduction) The FragmentManager allows you to Get the fragments associated with an activity Create fragment transaction, which, in turn, affect the back stack beginTransaction – starts a series of edit operations on the fragments associated with this fragmentManager The method returns a FragmentTransaction

Managing Fragments Using the FragmentManager you can Get activity fragments with findFragmentById() or findFragmentByTag Pop fragments off the back stack with popBackStack() Acts like the user clicking the back button Register a listener for back stack changes with addOnBackStackChangedListener()

The Back Stack (Introduction) Back navigation is how users move backward through the history of previously visited screens Use the Android Back button to do this Do not add a back button to the UI Ordinarily, the system builds the back stack as the user navigates from one activity (fragment) to the next Use the FragmentTransaction to manage the back stack

The FragmentTransaction call beginTransaction() to start a fragment transaction and commit() to cause the changes to take effect In between the two call add places one fragment on top of another fragment replace causes the current fragment to be destroyed specified fragment created

The FragmentTransaction (Example) Create a fragment and transaction,

Fragment (Best Practices) The following methods are commonly implemented Display a floating dialog with DialogFragment Display a list with ListFragment Create a setting activity with PreferenceFragment