DialogFrag#show() from a Fragment throwing “IllegalStateException: Can not perform this action after onSaveInstanceState”

前端 未结 1 541
梦毁少年i
梦毁少年i 2020-12-15 08:16

Just to be clear, I have read the dozen top SO questions on \"IllegalStateException: Can not perform this action after onSaveInstanceState\" and I have read Alex Lockwood\'s

相关标签:
1条回答
  • 2020-12-15 08:34

    OK, as far as I can tell this is a bug in the AOSP as I have also seen an instance of this from pure Android stack (ie nothing of my code at all).

    So it looks like there is a threading issue in the Activity/Fragment lifecycle in which a UI thread can get priority to respond to a button click AFTER the Activity/Fragment has already saved it's state.

    My work around which has been 100% successful so far is to catch the IllegalStateException and schedule the dialog show for the next time the Activity/Fragment becomes active using a PauseHandler https://stackoverflow.com/a/25322330/493682

    0 讨论(0)
提交回复
热议问题