DialogFragment callback on orientation change

前端 未结 5 583
执笔经年
执笔经年 2021-02-01 20:40

I\'m migrating my dialogs, currently using Activity.showDialog(DIALOG_ID);, to use the DialogFragment system as discussed in the android reference.

5条回答
  •  不要未来只要你来
    2021-02-01 21:21

    Another way is that you can stop the activity getting recreated. You have to tell Android that you'll handle the orientation change yourself and android won't recreate your activity. You need to add this for your activity to your manifest file:

    android:configChanges="keyboardHidden|orientation"
    

    If not this, then you can use standard onSaveInstanceState() to save your state and recover using savedInstanceState as recommended by Google.

    Here's Google's official guide for it: http://developer.android.com/guide/components/activities.html#Lifecycle

    Go through it if you haven't already. It'll really help you in android development.

提交回复
热议问题