I want to use monodroid to develop an android application which runs as a background service.
Can anyone provide a pointer to sample code on how to do this?
Thanks!
I have a basic service example in one of my samples on GitHub. The basic idea is that you define a class that extends Service
and decorate it with the Service attribute in order to generate the appropriate configuration in AndroidManifest.xml (you could optionally do that yourself, but you should rarely need to).
[Service]
public class MusicService : Service
{
public override IBinder OnBind(Intent intent)
{
return null;
}
public override void OnCreate()
{
base.OnCreate();
// ...
}
public override void OnStart(Intent intent, int startId)
{
base.OnStart(intent, startId);
// ...
}
public override void OnDestroy()
{
base.OnDestroy();
// ...
}
}
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