Forcing Android to not redraw activity on orientation change

前端 未结 8 889
小鲜肉
小鲜肉 2020-12-11 11:41

I have been going gaga to figure this out.
Although I have read a lot that on Orientation Change, Android kills an activity and starts it as a fresh one, and the only w

相关标签:
8条回答
  • 2020-12-11 12:19

    Yes, you can add attribute android:configChanges="orientation" to the activity declaration in the AndroidManifest.xml file.

    IMHO, it's better to declare android:configChanges="orientation|keyboard|keyboardHidden"

    About the blog post you gave the link in another answers. I guess here is the answer:

    If your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the Activity restart, then you can declare that your Activity handles the configuration change itself, which prevents the system from restarting your Activity.

    I spoke as well with an android developer about this problem. And he meant following. If you don't have different layouts for landscape and portrait orientation, you can easy use configChanges.

    0 讨论(0)
  • 2020-12-11 12:25

    if you are doing a lot of networking inside Asynchronous task maybe you should use onRetainNonConfigurationInstance() ans then get the data back in your onCreate() method like this tutorial or this

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