Fragment and Navigation Review (Video)

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/34

flashcard set

Earn XP

Description and Tags

30 practice flashcards covering fragment lifecycle, static and dynamic fragments, dual-pane layouts, and Jetpack Navigation concepts from the lecture notes.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

35 Terms

1
New cards

What is a Fragment in Android?

A modular UI component that represents a portion of an Activity's UI and can be reused across multiple activities.

2
New cards

How is the fragment lifecycle related to the Activity lifecycle?

The fragment lifecycle is bound to the Activity lifecycle; fragment callbacks are interleaved with the Activity's lifecycle.

3
New cards

Name five common Fragment lifecycle callbacks.

onAttach, onCreate, onCreateView, onViewCreated, onStart (with onResume as the next step).

4
New cards

Which callback creates the fragment's UI?

onCreateView.

5
New cards

Which callback is typically used to set up the fragment's views after the layout is created?

onViewCreated.

6
New cards

What is the difference between static and dynamic fragments?

Static fragments are defined in the activity's layout XML; dynamic fragments are added or replaced at runtime via FragmentManager.

7
New cards

What is a dual-pane layout?

A layout that shows two panes on larger screens to display, for example, a list and a detail simultaneously.

8
New cards

What does the sw600dp qualifier indicate?

A resource qualifier indicating devices with a smallest width greater than 600 dp (usually 7-inch tablets and larger).

9
New cards

What is Jetpack Navigation used for?

To simplify navigation between fragments and activities using a graph of destinations and actions.

10
New cards

What is a navigation graph?

An XML resource defining destinations (fragments/activities) and actions that connect them.

11
New cards

How do you add a static fragment to an activity layout?

By including a fragment tag in the layout with android:name set to the fragment class.

12
New cards

How can you create a two-fragment layout with proportional space?

Place two fragment elements in a vertical LinearLayout with layoutheight 0dp and assign layoutweight values to divide space.

13
New cards

How do you pass data to a fragment using a Bundle?

Create a Bundle with key-value pairs and set it as the fragment's arguments before adding it.

14
New cards

What is a fragment factory method and how is it used?

A companion object newInstance(param) that returns a Fragment with its arguments set, enabling parameterized fragments.

15
New cards

What is FragmentContainerView?

A container view that hosts fragments and works well with Jetpack Navigation.

16
New cards

In a dual-pane layout, how does an activity update the detail pane when a list item is selected?

It checks isDualPane; if true, it updates the detail fragment; otherwise, it starts a separate DetailActivity.

17
New cards

What does addToBackStack(null) do in fragment transactions?

Adds the transaction to the back stack so the user can press back to return to the previous fragment.

18
New cards

How can fragments communicate with their hosting activity?

Define a listener interface in the fragment; the activity implements it and the fragment calls the callback.

19
New cards

What steps are involved in using Jetpack Navigation in an app?

Add a NavHostFragment, create a nav_graph.xml with destinations and actions, and wire the host to use the graph.

20
New cards

How can you navigate between destinations using a fragment's view with Navigation?

Use a navigate action, e.g., Navigation.createNavigateOnClickListener(actionId, bundle), or navigate via a NavController.

21
New cards

What is the difference between add() and replace() in FragmentTransaction?

add() inserts a fragment without removing existing ones; replace() removes the existing fragment(s) in the container and adds the new one.

22
New cards

In a two-pane UI, how do you decide between updating detail vs starting a new activity?

Use a boolean isDualPane; if true, update DetailFragment; if false, start DetailActivity.

23
New cards

How do you implement dynamic fragments with a FragmentContainerView?

Use FragmentContainerView as the container and perform fragment transactions (add/replace) at runtime to display fragments.

24
New cards

What is the purpose of the layout-sw600dp resource directory?

To provide tablet-optimized layouts for devices with sw600dp or larger.

25
New cards

How can you implement a color-changing feature with fragments?

Create a ColorFragment with OnClickListeners on color buttons that modify a TextView's color in the fragment.

26
New cards

What does DetailFragment.setStarSignData(starSignId) do?

It updates the DetailFragment's UI with the corresponding star sign data (name, symbol, date range) based on the ID.

27
New cards

How do you pass data to DetailFragment using a factory method?

Use DetailFragment.newInstance(starSignId) to create the fragment with STARSIGNID in arguments.

28
New cards

What is a major advantage of Jetpack Navigation over manual fragment management?

It reduces boilerplate, handles back navigation, and centralizes navigation in a graph.

29
New cards

Where do you place a navigation graph file and what is it called typically?

In res/navigation/nav_graph.xml; NavHostFragment uses it to manage destinations.

30
New cards

How do you adapt static dual-pane layouts for phones vs tablets?

Provide separate layouts in res/layout and res/layout-sw600dp to present different fragment arrangements and space allocations.

31
New cards

What is a Fragment lifecycle order for initial display (from creation to display)?

onAttach, onCreate, onCreateView, onViewCreated, onActivityCreated, onStart, onResume.

32
New cards

What is the role of a ListFragment in the dual-pane navigation example?

It displays a list of items and notifies when an item is selected to update detail or start a new screen.

33
New cards

How do you implement a DetailActivity for non-dual-pane devices?

Launch a separate activity (DetailActivity) to show details when isDualPane is false.

34
New cards

What is a NavHostFragment used for in Jetpack Navigation?

A fragment that acts as a host for navigation, swapping between destinations defined in nav_graph.

35
New cards

Why is a factory method used with DetailFragment in dynamic fragments?

To pass arguments (like STARSIGNID) when creating the fragment instance.