Download presentation
Presentation is loading. Please wait.
1
Mobile Applications (Android Programming)
Semester II Dr. Saman Mirza Abdullah
2
Class Objective The objective of this class is:
To learn and understand Fragments. To learn the functions that needed to build fragments. Mobile Application - Ishik
3
Fragments Fragment is an Android programming aspect that represents a portion of the user interface of what a user sees on the application window. The Android documentation describes Fragment as a portion of user interface in an Activity Object. This means an Activity object can be composed of one or more fragments, each having its own user interface definition. Developers can combine one or more fragments to build a single activity or even reuse fragments across multiple activities Mobile Application - Ishik
4
With (out) Fragments Without fragments, classically, developers would have to build a new Activity whenever the user interacted with the application. With Fragments, developers now can update another portion of the UI on the screen that corresponds to the user selection,, without needing to move the user to another screen” Mobile Application - Ishik
5
Fragments Fragments provide for developers ability to create a dynamic and multi-pane user interface on Android. You need to encapsulate UI components and activity behaviors into modules that you can swap into and out of your activities Fragment behaves somewhat like a nested activity that can define its own layout and manage its own lifecycle. Mobile Application - Ishik
6
Fragment’s Lifecycle A fragment must always be embedded in an activity and the fragment's lifecycle is directly affected by the host activity's lifecycle. For example, when the activity is paused, so are all fragments in it, and when the activity is destroyed, so are all fragments However, while an activity is running you can manipulate each fragment independently, such as add or remove them. Mobile Application - Ishik
7
Fragment and Back button
When fragment performs a transaction, a back stack can be added. It can managed by the activity Each back stack entry in the activity is a record of the fragment transaction that occurred. The back stack allows the user to reverse a fragment transaction (navigate backwards), by pressing the Back button. Mobile Application - Ishik
8
Fragment and Back button
When fragment performs a transaction, a back stack can be added. It can managed by the activity Each back stack entry in the activity is a record of the fragment transaction that occurred. The back stack allows the user to reverse a fragment transaction (navigate backwards), by pressing the Back button. Mobile Application - Ishik
9
Fragment Philosophy Mobile Application - Ishik
10
Fragment’s Lifecycle Mobile Application - Ishik
11
Creating Fragments Fragments can be crated using subclasses.
It has the following callback methods: onCreate() onCreatView() onPause() Mobile Application - Ishik
12
Fragment – onCreat() The system calls this method when creating the fragment. It needs to initialize essential components of the fragment, when wants to retain on the following states: On paused On stopped, or On resumed. Mobile Application - Ishik
13
Fragment – onCratView()
The system calls this method when the fragment needs to draw its users interface for the first time. It needs the View return methods to view the fragment. Mobile Application - Ishik
14
Fragment – onPause() The system calls this method as the first indication that the user is leaving the fragment. The onCommit () method will be involved. Mobile Application - Ishik
15
Crating a Fragment Crating a subclass from Fragments main class.
This needed to tell that there is a Fragment in this activity. Mobile Application - Ishik
16
Crating a Fragment The parameters of crating the Fragments are automatically working in your code. Mobile Application - Ishik
17
Crating a Fragment The return inflate method.
Mobile Application - Ishik
18
Mobile Application - Ishik
19
Adding Fragments Fragments need to be added inside the Activity.
Mobile Application - Ishik
20
Class End Mobile Application - Ishik
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.