Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

monodroid for android service

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!

like image 925
user43737 Avatar asked Dec 27 '22 18:12

user43737


1 Answers

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();

        // ...
    }
}
like image 57
Greg Shackles Avatar answered Jan 13 '23 03:01

Greg Shackles