I have the following problem: I have an android application written with Kotlin.
The application has two Activities.
From the fist one navigate to the second one like this:
val intent = Intent(firstActivity, SecondActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_NEW_TASK
startActivity(intent)
firstActivity?.finish()
In the second Activity I overwrite the method onBackPressed like this:
override fun onBackPressed() {
val count = supportFragmentManager.backStackEntryCount
if(count == 0) {
// Dialog to ask the user if he want to quit the application
else{
super.onBackPressed()
}
}
But when I press the back button while I am in the second Activity everytime the count of the BackStack is 0.
When I remove the if statement and only call super.onBackPressed() the fragment in the Activity is setted back to the last fragment so I assume that the BackStack is working.
How do I get the value of the BackStackCount?
Edit: In both of my Activities I have multiple Fragments.
Thank you for your help!
question from:
https://stackoverflow.com/questions/65829969/android-kotlin-get-the-count-of-the-backstack-in-a-second-activity 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…