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 d85ef9b6..e966fcd9 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/running/RunningActivity.kt @@ -20,7 +20,7 @@ import com.whyranoid.presentation.databinding.ActivityRunningBinding import com.whyranoid.presentation.util.dateToString import com.whyranoid.presentation.util.repeatWhenUiStarted import dagger.hilt.android.AndroidEntryPoint -import java.util.* +import java.util.Date @AndroidEntryPoint internal class RunningActivity : @@ -89,36 +89,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() @@ -135,11 +110,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 00000000..b7d0a034 --- /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) + } +}