Professional Documents
Culture Documents
1.2 Fragment Lifecycle and Communications
1.2 Fragment Lifecycle and Communications
1.2 Fragment Lifecycle and Communications
Fragments
Lesson 1
This
Thiswork
workisislicensed
licensedunder
underaa
Advanced Android Development Fragments Creative
CreativeCommons
CommonsAttribution
Attribution4.0
4.0Inter
Inter 1
national
nationalLicense
License
1.2 Fragment lifecycle and
communications
Using the Fragment lifecycle and
communicating with an Activity
● Activity (host)
Activity
onDestroyView()
○ Paused Paused
○ Stopped
fragmentTransaction.add(R.id.fragment_container, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
● In Activity:
○ All Activity classes using Fragment must implement interface
○ Use the interface callback method(s) to retrieve data
interface OnFragmentInteractionListener {
void onRadioButtonChoice(int choice);
}
@Override
public void onRadioButtonChoice(int choice) {
mRadioButtonChoice = choice;
// Use mRadioButtonChoice in Activity
// ...
}
● Concept chapter:
1.2 Fragment lifecycle and communications
● Practical: 1.2 Communicating with a Fragment