29.3 Adding a Fragment to an Activity using the Layout XML File
Fragments may be incorporated into an activity either by writing Java code or by embedding the fragment into the activity’s XML layout file. Regardless of the approach used, a key point to be aware of is that when the support library is being used for compatibility with older Android releases, any activities using fragments must be implemented as a subclass of FragmentActivity instead of the AppCompatActivity class:
package com.example.myfragmentdemo;
import android.os.Bundle;
import androidx.fragment.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState...