Android s nt Fragme Android Fragments Lecture Outcomes

  • Slides: 18
Download presentation
Android s nt Fragme Android Fragments

Android s nt Fragme Android Fragments

Lecture Outcomes At the end of this lecture you will be able to; •

Lecture Outcomes At the end of this lecture you will be able to; • Understand Android Fragments. • Understand Lifecycle of Fragment with lifecycle methods.

Fragments • A Fragment is a piece of an activity which enable more modular

Fragments • A Fragment is a piece of an activity which enable more modular activity design. It will not be wrong if we say, a fragment is a kind of sub-activity.

Fragments • A fragment has its own layout and its own behavior with its

Fragments • A fragment has its own layout and its own behavior with its own life cycle callbacks.

Fragments • A fragment has its own layout and its own behavior with its

Fragments • A fragment has its own layout and its own behavior with its own life cycle callbacks. • You can add or remove fragments in an activity while the activity is running.

Fragments • You can combine multiple fragments in a single activity to build a

Fragments • You can combine multiple fragments in a single activity to build a multi-pane UI.

Fragments • You can combine multiple fragments in a single activity to build a

Fragments • You can combine multiple fragments in a single activity to build a multi-pane UI. • A fragment can be used in multiple activities.

Fragments • You can combine multiple fragments in a single activity to build a

Fragments • You can combine multiple fragments in a single activity to build a multi-pane UI.

Fragments • You can combine multiple fragments in a single activity to build a

Fragments • You can combine multiple fragments in a single activity to build a multi-pane UI. • Fragment life cycle is closely related to the life cycle of its host activity which means when the activity is paused, all the fragments available in the activity will also be stopped.

Fragments • We can insert the fragment into activity layout by using <fragment> element

Fragments • We can insert the fragment into activity layout by using <fragment> element and by dividing the layout of activity into fragments, we can modify the appearance of an app design at runtime. • We can also implement a fragment without having any user interface (UI).

Fragments • It’s an optional to use fragments into activity but by doing this

Fragments • It’s an optional to use fragments into activity but by doing this it will improve the flexibility of our app UI and make it easier to adjust our app design based on the device size.

Fragments

Fragments

Fragments • For example, GMAIL app is designed with multiple fragments, so the design

Fragments • For example, GMAIL app is designed with multiple fragments, so the design of GMAIL app will be varied based on the size of device such as tablet or mobile device.

Life Cycle

Life Cycle

Fragment Life Cycle • Following are the list of methods which will perform during

Fragment Life Cycle • Following are the list of methods which will perform during the lifecycle of fragment in android applications. Method Description on. Attach() It is called when the fragment has been associated with an activity. on. Create() It is used to initialize the fragment. on. Crete. View() It is used to create a view hierarchy associated with the fragment.

Fragment Life Cycle on. Activity. Created() It is called when the fragment activity has

Fragment Life Cycle on. Activity. Created() It is called when the fragment activity has been created and the fragment view hierarchy instantiated. on. Start() It is used to make the fragment visible. on. Resume() It is used to make the fragment visible in an activity. on. Pause() It is called when fragment is no longer visible and it indicates that the user is leaving the fragment.

Fragment Life Cycle on. Stop() It is called to stop the fragment using the

Fragment Life Cycle on. Stop() It is called to stop the fragment using the on. Stop() method. on. Destory. View() The view hierarchy associated with the fragment is being removed after executing this method. on. Destroy() It is called to perform a final clean up of the fragments state. on. Detach() It is called immediately after the fragment disassociated from the activity.