Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

Starting a service on demand

I have a service that works fine if i let it start in the AndroidManifest like

<service android:name="com.company.BackgroundUploader" />

I would like to start this service only when it is needed so added a enabled="false" to a service:

<service android:name="com.company.BackgroundUploader" android:enabled="false" />

i then programmatically re-enable it and try to start it

Application.Context.PackageManager.SetComponentEnabledSetting(new ComponentName(Application.Context, "com.company.BackgroundUploader"), ComponentEnabledState.Enabled, ComponentEnableOption.None);
Type serviceType = Type.GetType("com.company.BackgroundUploader");
Application.Context.StartService(new Intent(Application.Context, serviceType));

however the StartService call throws an exception

type Parameter name: Type is not derived from a java type.

with not much more information .
can anyone see what i am missing here ?

thanks

Tagged:

Best Answer

Answers

Sign In or Register to comment.