Android orientation change calls onCreate

后端 未结 3 2191
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 18:28

I\'ve made a search screen that has one tab for keywords, filters, and a search button, and three optional tabs for the different types of results (each containing a L

3条回答
  •  余生分开走
    2020-12-01 18:58

    What you describe is the default behavior. You have to detect and handle these events yourself by adding:

    android:configChanges
    

    to your manifest and then the changes that you want to handle. So for orientation, you would use:

    android:configChanges="orientation"
    

    and for the keyboard being opened or closed you would use:

    android:configChanges="keyboardHidden"
    

    If you want to handle both you can just separate them with the pipe command like:

    android:configChanges="keyboardHidden|orientation"
    

    This will trigger the onConfigurationChanged method in whatever Activity you call. If you override the method you can pass in the new values.

    Hope this helps.

提交回复
热议问题