Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Java.Lang.IllegalStateException: System services not available to Activities before onCreate()

$
0
0

My Android App gets the Exception:

Java.Lang.IllegalStateException: System services not available to Activities before onCreate().

This is the code part throwing the exception:

WifiManager wifiManager;
try
{
    wifiManager = this.GetSystemService(WifiService) as WifiManager;
}
catch (IllegalStateException ex)
{
    return false;
}

My MainActivity is:

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);

    Forms.Init(this, bundle);
    this.SetPage(App.GetMainPage());
}

So my OnCreate is called and as far as i know X.Forms uses only one activity. So how can this happen?
My app needs to access the WifiService to work. Is this because i am in another thread?


Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>