Skip to content

Commit

Permalink
fix old fragments not run onDestroy with pushTo
Browse files Browse the repository at this point in the history
  • Loading branch information
seiko committed Dec 5, 2021
1 parent 776548a commit d93770f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ abstract class AbsBaseFragment(private val _supportBack: Boolean = true) : Fragm
@Suppress("DEPRECATION")
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
Log.e(TAG, "onActivityCreated:" + this.javaClass.simpleName)
Log.e(TAG, "onActivityCreated:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Log.e(TAG, "onViewCreated:" + this.javaClass.simpleName)
Log.e(TAG, "onViewCreated:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
view.findViewById<TextView>(R.id.title_name)?.text = titleName
if (_supportBack) {
view.findViewById<TextView>(R.id.title_back)?.let {
Expand All @@ -36,38 +36,38 @@ abstract class AbsBaseFragment(private val _supportBack: Boolean = true) : Fragm

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Log.e(TAG, "onCreate:" + this.javaClass.simpleName)
Log.e(TAG, "onCreate:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}

override fun onStart() {
super.onStart()
Log.e(TAG, "onStart:" + this.javaClass.simpleName)
Log.e(TAG, "onStart:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}

override fun onResume() {
super.onResume()
Log.e(TAG, "onResume:" + this.javaClass.simpleName)
Log.e(TAG, "onResume:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}

override fun onPause() {
super.onPause()
Log.e(TAG, "onPause:" + this.javaClass.simpleName)
Log.e(TAG, "onPause:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}

override fun onStop() {
super.onStop()
Log.e(TAG, "onStop:" + this.javaClass.simpleName)
Log.e(TAG, "onStop:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}


override fun onDestroy() {
super.onDestroy()
Log.e(TAG, "onDestroy:" + this.javaClass.simpleName)
Log.e(TAG, "onDestroy:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}

override fun onDestroyView() {
super.onDestroyView()
Log.e(TAG, "onDestroyView:" + this.javaClass.simpleName)
Log.e(TAG, "onDestroyView:${this.javaClass.simpleName}(${this.hashCode().toString(16)})")
}

protected abstract val titleName: String?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ class FragivityFragmentNavigator(

val prevFragment = if (isPushTo) {
backStack.clear()
fragmentManager.fragments.forEach { ft.remove(it) }
fragmentManager.fragments.reversed().forEach {
ft.remove(it)
if (it.mState == Fragment.STARTED) {
it.mState = Fragment.ACTIVITY_CREATED
}
fragmentManager.moveToState(it, Fragment.INITIALIZING)
}
fragmentManager.mBackStack?.clear()
null
} else {
Expand Down

0 comments on commit d93770f

Please sign in to comment.