I am playing with fragments in Android.
I know I can change a fragment by using the following code:
FragmentManager fragMgr = getSupportFragmentManag
Here is a Kotlin solution:
if ( this.getSupportFragmentManager().getBackStackEntryCount()>0 ) {
var fgmt = this.getSupportFragmentManager().fragments[this.getSupportFragmentManager().getBackStackEntryCount()-1]
if( fgmt is FgmtClassName ) {
(fgmt as FgmtClassName).doSth()
}
}
Simplified way:
with ( this.getSupportFragmentManager() ) {
if ( getBackStackEntryCount()>0 ) {
var fgmt = fragments[getBackStackEntryCount()-1]
if ( fgmt is FgmtClassName ) {
(fgmt as FgmtClassName).doSth()
}
}
}