Fragments: Introduction Fragments were introduced in Android 3.0 to support flexible and dynamic UI designs represent portions of an application’s user.

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.
CSE2102 Introduction to Software Engineering Lab 2 Sept/4/2013.
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,
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: 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.
Android Info mostly based on Pro Android 3.  User Applications  Java Libraries – most of Java standard edition ◦ Activities/Services ◦ UI/Graphics/View.
Mobile Programming Lecture 6
Copyright© Jeffrey Jongko, Ateneo de Manila University Of Activities, Intents and Applications.
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.
ANDROID L. Grewe Components  Java Standard Development Kit (JDK) (download) (latest version)  AndroidStudio.
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.
Mobile Programming Midterm Review
1 CMSC 628: Introduction to Mobile Computing Nilanjan Banerjee Introduction to Mobile Computing University of Maryland Baltimore County
Android Application Lifecycle and Menus
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.
1. 2 The Address Book app provides convenient access to contact information that’s stored in a SQLite database on the device. You can: scroll through.
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
Use conductor instead Gergely Szőke | Wanari
Open Handset Alliance.
Activity and Fragment.
Basic Activities and Intents
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
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.
CIS 470 Mobile App Development
Chapter 9: Fragments.
Activity Lifecycle Fall 2012 CS2302: Programming Principles.
Activities and Intents
CIS 470 Mobile App Development
Activity Lifecycle.
CIS 470 Mobile App Development
SE4S701 Mobile Application Development
Mobile Programming Dr. Mohsin Ali Memon.
Activities and Fragments
Korea Software HRD Center
Activities, Fragments, and Intents
Android Sensor Programming
CIS 694/EEC 693 Android Sensor Programming
Presentation transcript:

Fragments: Introduction Fragments were introduced in Android 3.0 to support flexible and dynamic UI designs represent portions of an application’s user interface Each fragment would contain its own set of views Have their own life cycle, receiving their own input events And can be added and removed to an activity at run time Their lifecycles are affected by the activity creating them If activity paused => all its associated fragments are paused as well If activity destroyed => associated fragments are also destroyed

Fragments: Creation To create a fragment You must subclass the Fragment class and override onCreateView()  The method called to draw the user interface of a fragment Example:

Adding a Fragment to an activity A fragment contributes a portion of the UI to host activity At any time, one can add fragments to an activity By using the FragmentTransaction class and By specifying a ViewGroup in which to place fragment Example FragmentManager fragmentManager = getFragmentManager() FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); ExampleFragment fragment = new ExampleFragment(); fragmentTransaction.add(R.id.fragment_container, fragment); fragmentTransaction.commit();

Fragment Transactions Fragment transactions Are performed by means of the FragmentTransaction class Each transaction is a set of changes performed at the same time And can be reversed by saving it to the back stack Example: // Create new fragment and transaction Fragment newFragment = new ExampleFragment(); FragmentTransaction transaction = getFragmentManager().beginTransaction(); // Replace whatever is in the fragment_container view with this fragment, // and add the transaction to the back stack transaction.replace(R.id.fragment_container, newFragment); transaction.addToBackStack(null); // Commit the transaction transaction.commit();

Fragments: Communicating with Activity A fragment is independent of an activity But, can be used inside multiple activities With a given instance being directly tied to the activity  Containing the fragment Can access its associated activity using getActivity() Likewise, an activity can access a fragment By acquiring a reference to the fragment via FragmentManager ExampleFragment fragment = (ExampleFragment) getFragmentManager().findFragmentById(R.id.example_fragment);

Fragments: FragmentManagementApp Refer to FragmentManagementApp project

Fragments: Life Cycle Like activities, fragments Have their own life cycle When a fragment is created onAttach, onCreate, onCreateView onActivityCreated becomes visible onStart, onResume goes into background mode onPause, onStop is destroyed onPause, onStop, onDestroyView, onDestroy, on Detach