diff --git a/TrackMySleepQualityFinal/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerFragment.kt b/TrackMySleepQualityFinal/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerFragment.kt index a71dd9575..b4b3bc8b9 100755 --- a/TrackMySleepQualityFinal/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerFragment.kt +++ b/TrackMySleepQualityFinal/app/src/main/java/com/example/android/trackmysleepquality/sleeptracker/SleepTrackerFragment.kt @@ -71,14 +71,14 @@ class SleepTrackerFragment : Fragment() { // Specify the current activity as the lifecycle owner of the binding. // This is necessary so that the binding can observe LiveData updates. - binding.setLifecycleOwner(this) + binding.lifecycleOwner = this // Add an Observer on the state variable for showing a Snackbar message // when the CLEAR button is pressed. - sleepTrackerViewModel.showSnackBarEvent.observe(this, Observer { + sleepTrackerViewModel.showSnackBarEvent.observe(viewLifecycleOwner, Observer { if (it == true) { // Observed state is true. Snackbar.make( - activity!!.findViewById(android.R.id.content), + requireActivity().findViewById(android.R.id.content), getString(R.string.cleared_message), Snackbar.LENGTH_SHORT // How long to display the message. ).show() @@ -89,7 +89,7 @@ class SleepTrackerFragment : Fragment() { }) // Add an Observer on the state variable for Navigating when STOP button is pressed. - sleepTrackerViewModel.navigateToSleepQuality.observe(this, Observer { night -> + sleepTrackerViewModel.navigateToSleepQuality.observe(viewLifecycleOwner, Observer { night -> night?.let { // We need to get the navController from this, because button is not ready, and it // just has to be a view. For some reason, this only matters if we hit stop again