public class ReportFragment extends Fragment { ... public void onActivityCreated(Bundle savedInstanceState) { dispatch(Lifecycle.Event.ON_CREATE); } public void onStart() { dispatch(Lifecycle.Event.ON_START); } public void onResume() { dispatch(Lifecycle.Event.ON_RESUME); } public void onPause() { dispatch(Lifecycle.Event.ON_PAUSE); } public void onStop() { dispatch(Lifecycle.Event.ON_STOP); } ... }
Step3 : register it at onResume override fun onResume() { super.onResume() val filter = IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION) registerReceiver(receiver, filter) } register at onResume
Lifecycle Management - is a hard and hassle task - can cause problems The Lifecycle library - provides the feature to observe lifecycles - can create lifecycle-aware components easily