posted 6 years ago
I found a workaround that works flawlessly. I found out that when the phone leaves the app, it kills all the instance variables. However, it saves the static variables. I don't know why. Do you know why? I noticed this as I started creating what I wanted saved as static variables. I then decided a very good way of doing it would be to make the entire Game instance a static instance. When I do this, the exact state of the game is saved. I can be shooting at an enemy, while another enemy is in the middle of exploding, and when I close the app and reopen, it continues exactly at that state.
Weird, but whatever, it works. Why is it the instance objects are deleted but everything static remains? What I do now is reinstantiate the GamePanel and MainThread, and I think the SurfaceHolder too, and I have a static Game object and static boolean that keeps track of whether or not the Game object has already been instantiated. If not (as in first load), it instantiates it.