Android app resets on orientation change, best way to handle?

后端 未结 5 591
余生分开走
余生分开走 2021-01-03 08:02

So I am making a basic chess app to play around with some various elements of android programming and so far I am learning a lot, but this time I am lost.

When the o

5条回答
  •  梦谈多话
    2021-01-03 08:25

    in your manifest in the tag, you can add android:configChanges="orientation|keyboardHidden", this will stop the activity from reloading and call onConfigurationChanged() instead when the orientation is changed or the keyboard is hidden.

    If you need to make adjustments when either of these events happen, you can override onConfigurationChanged() in your activity, if not all you have to do is add the property to the manifest.

    Something like:

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setContentView(R.layout.myLayout);
    }
    

    works perfectly well.

提交回复
热议问题