How to keep Popup window opened when orientation changes at run time in Android?

前端 未结 4 1977
夕颜
夕颜 2020-12-19 07:12

I have created a Popup window which contains month view to pick up date. When I changes orientation, due to Android loads an activity all over again my popup Window gets dis

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-19 07:34

    Whenever there is an orientation change, Android destroys your activity ( calls onDestroy()) and then restarts it (calls onCreate()).
    As soon as your popup is up, set a flag popup_open=1. Your popup will naturally have a dismiss button. Set the flag=0 in the click handler of this button. You can then re-open the popup when the app restarts in the method onRestoreInstanceState() or in the onCreate(). Here you would make a check for the flag. If the flag is set to 1, bring up the popup. So even if the orientation changed while the popup was up, onRestoreInstanceState() will know what to do based onthe state of the flag. For more reference check: How to handle runtime changes.

提交回复
热议问题