I am using Xamarin Forms to display a HybridWebView control from
The issue is I would like to set the KeepScreenOn flag, however the Window.AddFlags method cannot be called from a static context, but as far as I'm aware, there is no activity readily accessible
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
In the Shared project, I have App.xaml.cs which calls:
MainPage = new Project_App.MainPage();
Which is then in MainPage.xaml.cs
public MainPage()
{
InitializeComponent();
var hybridWebView = new HybridWebView {};
Content = hybridWebView;
}
And finally in the .Droid Project, I have HybridWebViewRenderer.cs
public class HybridWebViewRenderer : ViewRenderer<HybridWebView, Android.Webkit.WebView> {
Android.Webkit.WebView webView = null;
protected override void OnElementChanged(ElementChangedEventArgs<HybridWebView> e) {
webView = new Android.Webkit.WebView(Forms.Context);
}
I also have a MainActivity.cs in the .Droid project
[Activity(Label = "Project_App", MainLauncher = true]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity {
protected override void OnCreate(Bundle bundle) {
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
Window.AddFlags(WindowManagerFlags.KeepScreenOn);
LoadApplication(new Project_App.App());
}
}
However, putting Window.AddFlags in this file does not keep the screen active, and putting a breakpoint on this line never gets hit, however removing this entire file causes the app to fail to launch
Why is the breakpoint in the last file never hit, or alternatively, how can I get a reference to the activity so I can call AddFlags from a method in the HybridWebViewRenderer.cs class?