Reputation: 109
I have a BottomSheetDialogFragment with the default enter and exit animation. When the lifecycle chages (eg. go to home screen and return to the app) the bottomsheet starting animations plays.
I have tried disabling animations with setWindowAnimations(-1)
, however this also disables the exit animation when closing the dialog, which is not an option.
I show my bottomsheet this way:
MyBottomSheet.newInstance( ... ).show(parentFragmentManager, null)
Upvotes: 1
Views: 1977
Reputation: 4206
You should do that in onPause() instead of onStop(). Check this answer.
override fun onPause() {
super.onPause()
dialog?.window?.setWindowAnimations(-1)
}
To keep your animations when coming back, store the windowAnimation in a variable. You can retrieve the current animations with: dialog?.window?.attributes?.windowAnimations
Then save it in onSaveInstanceState and once the App is resumed, just call setWindowAnimations again and set your saved animation.
Upvotes: 4
Reputation: 39
Try using in onStop():
override fun onStop() {
super.onStop()
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
dialog?.window?.setWindowAnimations(-1)
}
}
Upvotes: 1