สร้าง Fragment ขึ้นมาใหม่ชื่อ FirstFragment
FirstFragment.java
package com.phaisarn.myapplication; import android.app.Activity; import android.os.Bundle; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; /** * A simple {@link Fragment} subclass. */ public class FirstFragment extends Fragment { public FirstFragment() { // Required empty public constructor } @Override public void onAttach(Activity activity) { super.onAttach(activity); Log.i("Check", "onAttach"); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i("Check", "onCreate"); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.fragment_first, container, false); } @Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.i("Check", "onActivityCreated"); } @Override public void onStart() { super.onStart(); Log.i("Check", "onStart"); } @Override public void onResume() { super.onResume(); Log.i("Check", "onResume"); } public void onPause() { super.onPause(); Log.i("Check", "onPause"); } public void onStop() { super.onStop(); Log.i("Check", "onStop"); } public void onDestroyView() { super.onDestroyView(); Log.i("Check", "onDestroyView"); } public void onDestroy() { super.onDestroy(); Log.i("Check", "onDestroy"); } public void onDetach() { super.onDetach(); Log.i("Check", "onDetach"); } }
Link