Android lifecycle of thread-based game
- by ehehhh
I ran into a bit of trouble while trying to get my game to work correctly after being put to the background by the user or a phone call for example.
My app has a SurfaceView class called GameView, which has the onDraw() method to do all the necessary drawing for my game and two threads - one for calling the onDraw() and one for doing the necessary calculations for the game's logic.
I succesfully implemented onPause() and onResume(). (I paused both threads when back button was pressed and resumed them after user cancelled in the AlertDialog.)
Now I would like to have the game paused the same way when onStop() gets called. I put both threads on pause and saved my characters location in the savedInstanceState, but when I start my app again, no method gets called (I checked with Logcat). I believe onRestart() should be called first, then onStart() and then onResume(), but none of that happens. What am I doing wrong?
(Didn't include any code, because it seems to be a problem of me not understanding the lifecycle, not a problem in code. If it seems necessary, I'll post the parts you request.)