I was targeting android 4.4 and was starting a service like this
start.Click += delegate {
StartService(new Intent("com.xamarin.LocationService"));
start.Enabled = false;
stop.Enabled = true;
};
and it all worked fine. Now I am targeting 6.0 and find from this thread that this isn't secure, and I should do this:
Intent serviceIntent = new Intent(context,MyService.class);
context.startService(serviceIntent);
but I cannot work out what the arguments for 'new Intent()' should be. The class name is 'LocationActivity' but if I do this
serviceIntent = new Intent(this, typeof(LocationActivity));
context.startService(serviceIntent);
it compiles OK but the service doesn't actually start.
The marked answer in that thread also suggests this
Intent bi = new Intent("com.android.vending.billing.InAppBillingService.BIND");
bi.setPackage("com.android.vending");
but if I try that I find that 'Intent does not contain a definition for setPackage'.
So, can someone help me with a solution here? Thanks in advance.
If you want to start an activity you need to use StartActivity and not StartService Then use this but change from StartService to StartActivity.
From
serviceIntent = new Intent(this, typeof(LocationActivity));
context.startService(serviceIntent);
To
serviceIntent = new Intent(this, typeof(LocationActivity));
context.StartActivity(serviceIntent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With