When I click the back arrow, I would like to go back to the previous screen, but have the previous fragment running in the background.
I tried this:
val start = Intent(Intent.ACTION_MAIN) start.addCategory(Intent.CATEGORY_HOME) start.flags = Intent.FLAG_ACTIVITY_NEW_TASK startActivity(start)
I would like the application to run in the background but not to leave it.
CodePudding user response:
you can run fragment in background while you are in another activity
finish()
this will finish the activity to the previous activity
CodePudding user response:
To keep the previous fragment running in the background and return to the previous screen, you can use the following code to navigate back:
val fragmentManager = supportFragmentManager
fragmentManager.popBackStack()
This will remove the current fragment from the back stack and return to the previous fragment that was running in the background. The previous fragment will remain in the background, and the activity will not be destroyed.