File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
app/src/main/java/com/github/droidworksstudio/launcher/ui/activities Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ import android.os.Looper
18
18
import android.view.Menu
19
19
import android.view.MenuItem
20
20
import android.view.WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
21
+ import androidx.activity.OnBackPressedCallback
21
22
import androidx.activity.viewModels
22
23
import androidx.annotation.RequiresApi
23
24
import androidx.appcompat.app.AppCompatActivity
@@ -214,6 +215,12 @@ class MainActivity : AppCompatActivity() {
214
215
// Retrieve the NavController
215
216
val navController = navHostFragment.navController
216
217
appBarConfiguration = AppBarConfiguration (navController.graph)
218
+
219
+ onBackPressedDispatcher.addCallback(this , object : OnBackPressedCallback (true ) {
220
+ override fun handleOnBackPressed () {
221
+ backToHomeScreen()
222
+ }
223
+ })
217
224
}
218
225
219
226
@SuppressLint(" SourceLockedOrientationActivity" )
@@ -259,13 +266,6 @@ class MainActivity : AppCompatActivity() {
259
266
super .onUserLeaveHint()
260
267
}
261
268
262
- @Deprecated(" Deprecated in Java" )
263
- override fun onBackPressed () {
264
- backToHomeScreen()
265
- @Suppress(" DEPRECATION" )
266
- super .onBackPressed()
267
- }
268
-
269
269
private fun backToHomeScreen () {
270
270
navController = findNavController(R .id.nav_host_fragment_content_main)
271
271
if (navController.currentDestination?.id != R .id.HomeFragment )
You can’t perform that action at this time.
0 commit comments