Fragment ?.

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.
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.
Android Fragments.
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.
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.
Android development basics Introduction,Structure,Development Boncho Valkov.Net Developer.
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.
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.
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.
More UI Action Bar, Navigation, and Fragments
Fragment Android Club Agenda Fragment Static fragment Dynamic fragment ViewPager.
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.
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.
Wiring Fragments Wiring Dialogs. Ask FragmentManager whether home Fragment exists If not, create home Fragment Add it Main Activity setContentView Launch.
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
Introduction to android
Android Application -Architecture.
Open Handset Alliance.
Basic Activities and Intents
Activities, Fragments, and Events
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.
Anatomy of an Android App and the App Lifecycle
Widgets & Fragments Kalin Kadiev Astea Solutions AD.
Android Mobile Application Development
Android 15: Fragments: API Guide
The Android Activity Lifecycle
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
Android training in Chandigarh. What is ADB ADB stands for Android Debug Bridge. It is a command line tool that is used to communicate with the emulator.
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
Programming Mobile Applications with Android
CIS 470 Mobile App Development
Activity Lifecycle.
Activities and Intents
Objects First with Java
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:

Fragment ?

What is a Fragment? Before android 3.0 , Activity 1 Activity 2 Before android 3.0 , If you have to show View 3 and View 4 you have to create new activity View 1 View 3 View 2 View 4

What is a Fragment? Now, just insert fragment or delete it and insert another fragment. Fragments are so much customizable. View 1 View 3 View 2 View 4 Fragment 1 Fragment 2 Activity 1 Activity 1

What is a Fragment? ACTIVITY Fragment is a chunk of UI. It has its own Lifecycle. It can process its own events It can be added or removed while the Activity runs. It was introduced in Honeycomb API 11. You can use Fragments on older devices using a Support Library from 1.6 to 2.3 FRAGMENT 1 FRAGMENT 2 ListView ImageView

Why do you need Fragments ? Combine Several Fragments in One Activity Reuse the same Fragment across several Activity Make better use of larger screen space on tablets

Uses of Fragments? Flexible user interfaces across different screen sizes Fixed/Scrolling/Swipe tab displays Dialog boxes

How to make a Fragment ? Extend Fragment class Provide apperarance in XML/Java Override onCreateView to link the appearance. Use the Fragment in XML/Java(Dynamically).

Activity Fragment OnCreate 1 onAttach is called after Fragment is associaiated with its Activity Gets a reference to the Activity object which can be used as Context. onCreateView. You are expected to return a View Hierarchy for your fragment onActivityCreated Called after Activity onCreate has completed execution Use this method to access/modify UI elements. 2 OnAttach OnAttachFragment 3 4 OnCreate 5 onCreateView 6 onActivityCreated onStart 7 8 onStart onResume 9 10 onResume

Activity Fragment 1 onPause onSaveInstanceState Use this to save information inside a Bundle object. onDestroyView Called after the Fragment View Hierarchy is no longer accessible onDestroy Called after fragment is not used. It still exists as a java object attached to the Activity onDetach Fragment is not tied to the Activity and does not have a View hierarchy onPause 2 3 onSaveInstanceState onSaveInstanceState 4 5 onStop onStop 6 7 onDestroyView 8 onDestroy 9 onDetach onDestroy 10

The Fragment Manager Every Activity has its own Fragment Manager Accessible through getFragmentManager() It maintains references to all fragments inside the Activity Use findFragmentById() or findFragmentByTag() to get reference to a particular Fragment. Fragment 1 Fragment Manager Fragment 3 Fragment 2

Fragment Transactions Fragement Manager Changes to the UI in terms of adding, Removing and replacing Fragments are Conducted as FragmentTransactions Begin a transaction Add, remove, replace whatever fragments you want Commit the transaction Fragement A begin commit

Inter-Fragment communication design Don’t maintain direct references of fragments within each other Crete an interface that contains the method which will act as an event carrier Let the Activity implement the interface Let Fragment 1 use the interface to send messages Use the callback method in Activity to trigger changes in Fragment 2 interface FragmentManager Activity Fragment 1 Fragment 2

Questions ?