Event.ACTIVATE been fired when i press power button on Android

I’m still having this issue: When i press power button of an Android device, to turn screen off, it fires an Event.DEACTIVATE and event.ACTIVATE.
I use these events to stop and resume sounds on my game. So, with this behaviour, my game still plays sound with the screen turned off, what I don’t want.

It works fine if i just change to another app and return after.

Is there a workarround?
Thanks.

I just tested with the latest OpenFL and Lime, and it triggered Event.DEACTIVATE from the stage when turning off the device or switching away, and Event.ACTIVATE when turning the device back on or switching back, as expected

package;


import openfl.display.Sprite;


class Main extends Sprite {
	
	
	public function new () {
		
		super ();
		
		trace ("START");
		
		stage.addEventListener (openfl.events.Event.ACTIVATE, function (_) {
			
			trace ("activate");
			
		});
		
		stage.addEventListener (openfl.events.Event.DEACTIVATE, function (_) {
			
			trace ("deactivate");
			
		});
		
	}
	
	
}

What version are you using?

Thank you :slight_smile:

I put your code on DisplayingABitmap sample and compile to android. When I switch the device off, it triggers Event.Deactivate and after a second, Event.Activate.
On Html5 it works properly.

I am using the latest version. Maybe it the NDK version? I’m using ndk-r14b.

OpenFL: 4.9.2
Lime: 4.0.3
hxcpp: 3.4.64

Thanks.

Strange, it doesn’t work this way on my device.

We are dispatching the ACTIVATE event when we get an SDL_APP_DIDENTERFOREGROUND event or SDL_WINDOWEVENT_SHOWN from SDL. I wonder which is triggering on your device.

Would you be willing to build Lime from the source? If I could recommend changes to Lime’s source code, and ask you to recompile Lime for Android, it would help identify what code path your device is going down

Thank you

I think I found whats is triggering the activate event.
It’s the Resize Event.
I put the Activate / Deactivate code on the Pirate Pig sample,
if I turn it off, in portrait orientation, it behaves as expected.
but when I put the phone in Landscape orientation, and turn it off, it fires the Deactivate + Activate events.

I will be out for a week, so I will not check the community.

Thanks.

I found a fix:

Thank you for your help in identifying this problem, my device behaved the same way in landscape, but now appears to work properly :slight_smile:

I’ve also notified the SDL2 team so this can be included in their next release

1 Like

Thanks. I’ve tested here and it’s working great.

1 Like