Reputation: 53
I am a developing game using andengine. When I press the power button, the onPause()
method is not being called. How do I fix the issue?
@Override
protected void onPause() {
//this method is not calling when press power button
super.onPause();
this.mEngine.onPause() ;
}
Upvotes: 3
Views: 2625
Reputation: 7694
Weird, haven't heard of it not being called. Let me research a bit.
Okay, pressing power should always call onPause()
, there seem to be some kind of bug in your code. Could you add some log calls to follow every step. and print the DDMS log.
Other possible problems:
It seems some devices misbehave and call onPause()
twice when pressing the power button.
In this case try using the powerManager to see if the screen is actually turned of.
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
if (pm.isScreenOn()) {
//now do stuff
}
Maybe onPause()
is called but onCreate()
is called right after ?
When you turn off the device, the lock screen is displayed. This typically forces the display to a particular orientation. If the screen is not currently in that orientation, it will need to be changed, and the top activity's configuration appropriately changed to match.
You can add config changes like this:
android:configChanges="keyboardHidden|orientation" android:configChanges="keyboardHidden|screensize"
To make sure this doesn't happen.
Upvotes: 2