diff --git a/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt index be226b3..aa9fccf 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt @@ -92,36 +92,11 @@ internal class RunningActivity : } } - override fun onStart() { - super.onStart() - mapView.onStart() - } - - override fun onResume() { - super.onResume() - mapView.onResume() - } - - override fun onPause() { - mapView.onPause() - super.onPause() - } - override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) mapView.onSaveInstanceState(outState) } - override fun onStop() { - mapView.onStop() - super.onStop() - } - - override fun onDestroy() { - mapView.onDestroy() - super.onDestroy() - } - override fun onLowMemory() { super.onLowMemory() mapView.onLowMemory() @@ -138,11 +113,12 @@ internal class RunningActivity : private fun initViews(savedInstanceState: Bundle?) { mapView = binding.mapView - mapView.onCreate(savedInstanceState) mapView.getMapAsync(this) binding.vm = viewModel + this.onBackPressedDispatcher.addCallback(this, backPressedCallback) + lifecycle.addObserver(RunningActivityObserver(mapView, savedInstanceState)) } private fun observeState() { diff --git a/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivityObserver.kt b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivityObserver.kt new file mode 100644 index 0000000..b7d0a03 --- /dev/null +++ b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivityObserver.kt @@ -0,0 +1,42 @@ +package com.whyranoid.presentation.running + +import android.os.Bundle +import androidx.lifecycle.DefaultLifecycleObserver +import androidx.lifecycle.LifecycleOwner +import com.naver.maps.map.MapView + +class RunningActivityObserver( + private val mapView: MapView, + private val savedInstanceState: Bundle? +) : DefaultLifecycleObserver { + + override fun onCreate(owner: LifecycleOwner) { + super.onCreate(owner) + mapView.onCreate(savedInstanceState) + } + + override fun onStart(owner: LifecycleOwner) { + super.onStart(owner) + mapView.onStart() + } + + override fun onResume(owner: LifecycleOwner) { + super.onResume(owner) + mapView.onResume() + } + + override fun onPause(owner: LifecycleOwner) { + mapView.onPause() + super.onPause(owner) + } + + override fun onStop(owner: LifecycleOwner) { + mapView.onStop() + super.onStop(owner) + } + + override fun onDestroy(owner: LifecycleOwner) { + mapView.onDestroy() + super.onDestroy(owner) + } +}