File tree 2 files changed +17
-2
lines changed
common/src/main/java/eu/kevin/common/architecture
demo/src/main/java/eu/kevin/demo/main
2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change 1
1
package eu.kevin.common.architecture
2
2
3
3
import android.content.Context
4
+ import android.os.Bundle
5
+ import androidx.activity.addCallback
4
6
import androidx.appcompat.app.AppCompatActivity
5
7
import androidx.fragment.app.Fragment
6
8
import androidx.fragment.app.commit
@@ -14,7 +16,15 @@ import eu.kevin.core.plugin.Kevin
14
16
15
17
abstract class BaseFragmentActivity : AppCompatActivity () {
16
18
17
- override fun onBackPressed () {
19
+ override fun onCreate (savedInstanceState : Bundle ? ) {
20
+ super .onCreate(savedInstanceState)
21
+
22
+ onBackPressedDispatcher.addCallback(this ) {
23
+ handleBackPress()
24
+ }
25
+ }
26
+
27
+ private fun handleBackPress () {
18
28
with (supportFragmentManager) {
19
29
fragments.lastOrNull { it.isVisible }?.let { fragment ->
20
30
if (fragment !is Navigable || ! fragment.onBackPressed()) {
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package eu.kevin.demo.main
2
2
3
3
import android.os.Bundle
4
4
import android.view.ViewGroup
5
+ import androidx.activity.addCallback
5
6
import androidx.appcompat.app.AppCompatActivity
6
7
import androidx.core.view.ViewCompat
7
8
import androidx.core.view.WindowCompat
@@ -56,9 +57,13 @@ internal class MainActivity : AppCompatActivity() {
56
57
}
57
58
}
58
59
}
60
+
61
+ onBackPressedDispatcher.addCallback(this ) {
62
+ handleBackPressed()
63
+ }
59
64
}
60
65
61
- override fun onBackPressed () {
66
+ private fun handleBackPressed () {
62
67
if (binding.mainFragmentContainer.currentItem == 0 ) {
63
68
finish()
64
69
} else {
You can’t perform that action at this time.
0 commit comments