Search code examples
androidair

Air for Android app is keeping screen awake when not in app


I have an air for android app that has event listeners for ACTIVATE and DEACTIVATE, inside the activate I tell the screen to stay awake and in the deactivate I tell it to go back to normal like so :

stage.addEventListener(Event.DEACTIVATE, deactivateHandler);
stage.addEventListener(Event.ACTIVATE, activateHandler);

protected function deactivateHandler(event:Event):void{
    SFX.disableSound();
    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.NORMAL;
}

protected function activateHandler(event:Event):void{
    NativeApplication.nativeApplication.systemIdleMode = SystemIdleMode.KEEP_AWAKE;
}

But the screen will stay awake at all times even when on the android home screen unless you force close the app... any ideas?

Thanks


Solution

  • You could try using this in your java code:

    // Gets one of the views visible on the screen and sets keepScreenOn to true.
    // This means the screen will stay on as long as the specified view is visible.
    this.findViewById(R.id.viewId).setKeepScreenOn(true);
    

    Or you could put android:keepScreenOn="true" in your layout.