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

Posted by Anthony Westover on Stack Overflow See other posts from Stack Overflow or by Anthony Westover
Published on 2010-05-05T15:36:08Z Indexed on 2010/05/05 15:38 UTC
Read the original article Hit count: 723

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 orientation of the emulator changes the activity gets reset. Based on my research the same thing will happen anytime the application is paused/interrupted, ie. keyboard change, phone call, hitting the home key etc.

Obviously, it is not viable to have a chess game constantly reset, so once again I find myself needing to learn how to fix this problem.

My research brings up a few main things, overriding the onPaused method in my Activity, listening for Orientation, Keyboard changes in my manifest (via android:configChanges), using Parcelables, or Serialization.

I have looked up a lot of sample code using Pacelables, but to be honest it is too confusing. Maybe coming back tomorrow with fresh eyes will be beneficial, but right now the more I look at Parcelables the less sense it makes.

My application utilizes a Board object, which has 64 Cell Objects(in an 8x8 2D array), and each cell has a Piece Object, either an actual piece or null if the space is empty. Assuming that I use either Parcelable or Serialization I am assuming that I would have to Parcelize or Serialize each class, Board, Cell, and Piece.

First and foremost, is Parcelable or Serialization even the right thing to be looking at for this problem? If so is either Parcelable or Serializable preferred for this? And am I correct in assuming that each of the three objects would have to be Parceled/Serialized? Finally, does anybody have a link to a simple to understand Parcelable tutorial? Anything to help me understand, and stop further headaches down the road when my application expands even further.

Any help would be appreciated.

© Stack Overflow or respective owner

Related posts about android

Related posts about orientation