Introducing fragments and the lifecycle
You probably remember from Chapter 2, First Contact: Java, XML, and the UI Designer, that the Java code in the Basic Activity template is not just contained in the MainActivity.java
file. There are also the FirstFragment.java
and SecondFragment.java
files. These files, we learned, contain the code that controls what happens when the user navigates between the two screens of the Basic Activity template app. The code inside these two files is different in structure from the MainActivity.java
file. Here is a quick peek at FirstFragment.java
:
public class FirstFragment extends Fragment { @Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) { ...