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

后端 未结 5 579
余生分开走
余生分开走 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:20

    When you save the board state, make an int[64] and at each position store the corresponding piece. So 0=empty, 1=white pawn, 2=white knight, etc...

    When you load the board state, iterate through the array and create the appropriate piece objects at the appropriate locations.

    You can convert the int[64] to a string to store in SharedPreferences, or use it with a Parcelable or whatever. Only store the minimum data you need.

提交回复
热议问题