1

I want my game to be able to continue from where its left before phone went to sleep(user press power button). My game work fine with home button. when user press home button and open game again, game start where it should be. But in the case user press power button(on google htc nexus one), it crashes. But when I test the game on samsung galaxy tablet 10, it works fine.

In LogCat, I could observe that when the user presses power button on galaxy tablet, onPause() is called. and when user press again onResume() is called which is normal.

But on google nexus, when the user press power button, onPause(), onResume(),onPause() is called respectively before it went into sleep. And nothing gets called when the user press power button again.

Please advice how can I fix the problem. Thanks in advance

EDIT

Looks like this problem is observed only on device that have portrait orientation by default.

midhunhk
  • 5,560
  • 7
  • 52
  • 83
someone_ smiley
  • 1,006
  • 3
  • 23
  • 42

1 Answers1

0

I manage to fix the problem by following answer to this question. After applying this solution, system did not crash any more. but after system wake, width and height was swapped. so in addition I have override

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
    if(width>height)
         gl.glViewport(0, 0, width, height);
    else gl.glViewport(0, 0, height, width);

}    

In this way i got my game back in landscape orientation.

Community
  • 1
  • 1
someone_ smiley
  • 1,006
  • 3
  • 23
  • 42