I am working with nested fragment and I am facing issue when I press back.
Flow:
FragementActivity
A(Fragment) B(Fragment)
C D E F
This is a structur of my application. Where C,D,E,F is child fragments and not added in back stack. D contains List fragment, and from DI called B. But When I press back from BI want again D with last selected position. I added A and B in back stack. How can I achieve this. Provide me some solutions. I recalled D but the selected position changed always.
您是否尝试重写方法onBackPressed()?
In addition to other functionality, you might have to call some functionality to hide the current visible fragment. I have attached snippet in Kotlin
override fun onBackPressed() {
// ...
val thisStep = myAdapter?.getItem(currentFragmentPosition) as MyFragmentStep
thisStep.setInvisible(runData)
}
//This goes on your activity ^^^
fun setInvisible(runData: Bundle) {
// ...
view?.visibility = View.INVISIBLE
}
//This goes on your base class of fragments ^^^
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.