1/18
Flashcards for lecture notes on Fragments and Navigation Components in Android app development.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
Fragment
A block of UI with its own lifecycle that can be reused within different activities, allowing developers to create modular user-interface components that can change based on screen size and orientation.
Fragment object
It is somewhere between a View and an Activity. Like a View, it can be added to a ViewGroup or be part of a layout, but unlike an Activity, it is not a Context, and its life cycle depends on that of the Activity to which it belongs.
onInflate
Fragment lifecycle method called only to define a fragment directly in the layout using the tag, saving configuration parameters and attributes defined in the XML layout file.
onAttach
Fragment lifecycle method called as soon as the fragment is attached to the father activity, used to store the reference about the activity.
onCreate
Fragment lifecycle step where the fragment is in the creation process, used to start threads to retrieve data, possibly from a remote server.
onCreateView
Fragment lifecycle method called when the fragment has to create its view hierarchy. During this method, layout will be inflated inside the fragment, but it is not sure that the activity is still created.
OnActivityCreated
Fragment lifecycle method that notifies when the father activity is created and ready for use. From here, the activity is active and created and can be used when needed.
onStart
Fragment lifecycle phase where the fragment is visible but not yet interacting with the user, similar to the activity's onStart.
onResume
Fragment lifecycle method called when the fragment is ready to interact with the user. At the end of this phase, the fragment is up and running.
onPause()
Similar to Activity.onPause()
onDestroyView()
Final fragment cleaning up. It is called if the OS decides to destroy the fragment view.
onDestroy()
Fragment lifecycle method where all active connections should be released because the fragment is close to shutting down.
onDetach
Fragment lifecycle method that detaches the fragment from the activity.
onStop()
Called when the fragment is no longer visible
FragmentManager
A component in the Activity used to handle fragments, allowing fragments to be added, removed, or replaced at runtime. A transaction is needed to activate any operations on a fragment.
Navigation
The interactions that allow users to navigate across, into, and back out from the different pieces of content within your app.
Navigation graph
An XML resource file that contains all navigation-related information in one centralized location, including destinations and the possible paths a user can take through the app.
NavHost
An empty container that displays destinations from your navigation graph. It contains a default NavHost implementation, NavHostFragment, that displays fragment destinations.
NavController
An object that manages app navigation within a NavHost, orchestrating the swapping of destination content as users move throughout your app.