I have written an application that plays music, using AndEngine. The annoying problem is that, when user presses power button or when screen automatically turns off, after pressing power button again, the application restarts and does not resume. I found this and this page, but they did not help me. Would you please help me? Thanks.
3 Answers
Simply add this line to your manifest file where you declared your activity
android:configChanges="orientation|keyboard|keyboardHidden"
for e.g
<activity android:name="com.algo.MainActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation|keyboard|keyboardHidden" />

- 21,688
- 25
- 143
- 191
Your AndEngine game has at least one Activity.
Each Activity has own lifetime cycle from onCreate to onDestroy. Take a look at picture and very detailed article here: Activities Lifecycle
Your game activity go though cycles and die automatically when user pressed PowerButton or BackButton. When you turn power on then activity starts from begin (onCreate).
You should implement save and load game functions and save game state on onPaused callback and load game state onResume callback. It will prevent from loosing state of your game between activity restarts.
Another good article about managing states for Android games: More Android Games that Play Nice

- 2,289
- 16
- 23
I found that this problem occurs in the following scenarios:
your Android phone is in portrait mode and your AndEngine application is in landscape mode, or your Android phone is in landscape mode and your AndEngine application is in portrait mode.
Try to make your application's orientation consistent with your Android system.

- 12,145
- 20
- 90
- 153