[0.20?] KeepAlive has no effect

This might not be 0.2 specific (could’ve been the same in 0.12), but this code has no effect in 0.2, neither on Preview (device) nor on Build:

"Mobile": {
  "KeepAlive": true

As a side question, I’d be curious to know of any hack/workaround the community uses to prevent the screen from dimming / locking while inactive.

Hey there cyril,

Good find! The actual answer is a little embarassing, it doesnt have any effect as it’s not used anywhere :expressionless:

Not sure how this one slipped through the net but I have created an issue to use this properly on platforms that support it.

We will let you know when this is fixed.

Thanks for posting!!

Hi Chris,

Should you or anyone else need it, here is the NativeModule to get this feature on Android. Require it into your App like any other module then use Module.KeepScreenOn() and Module.LetScreenOff() at will:

using Uno;
using Uno.Collections;
using Uno.Compiler.ExportTargetInterop;
using Fuse;
using Fuse.Scripting;

[ForeignInclude(Language.Java, "android.app.Activity", "android.view.WindowManager")]
public class ScreenModule : NativeModule
    public ScreenModule()
        AddMember(new NativeFunction("KeepScreenOn", (NativeCallback)KeepScreenOn));
        AddMember(new NativeFunction("LetScreenOff", (NativeCallback)LetScreenOff));

    static object KeepScreenOn(Context c, object[] args)

        return null;

    static object LetScreenOff(Context c, object[] args)

        return null;

    static extern(Android) void SetScreenFlagOn(bool visible)
        android.app.Activity rootActivity = @(Activity.Package).@(Activity.Name).GetRootActivity();

        rootActivity.runOnUiThread(new Runnable() {
            public void run() {
                // This code will always run on the UI thread, therefore is safe to modify UI elements.
                android.view.Window window = @(Activity.Package).@(Activity.Name).GetRootActivity().getWindow();
                if (visible) window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
                else window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);


    static extern(!Android) void SetScreenFlagOn(bool visible)
        debug_log "SetScreenFlagOn not available on this platform";

Good stuff, thanks for posting this!

This still seems to be an issue (0.35.0) on iOS / iPad. Any news on an update?