Background Services in Mono for Android: Listing 2

Overriding OnStartCommand()

public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
    {
        string command = intent.GetStringExtra(CommandExtraName);

        switch (command)
        {
            case PlayCommand:
                startPlaying();

                break;
            case StopCommand:
                stopPlaying();

                break;
            default:
                return base.OnStartCommand(intent, flags, startId);
        }

        return StartCommandResult.Sticky;
    }

About the Author

Greg Shackles, Microsoft MVP, Xamarin MVP, is a Principal Engineer at Olo. He hosts the Gone Mobile podcast, organizes the NYC Mobile .NET Developers Group, and wrote Mobile Development with C# (O'Reilly). Greg is obsessed with heavy metal, baseball, and craft beer (he’s an aspiring home brewer). Contact him at Twitter @gshackles.

comments powered by Disqus

Featured

  • New TypeScript 4.2 Tweaks Include Project Explainer

    Microsoft shipped TypeScript 4.2 -- the regular quarterly update to the open source programming language that improves JavaScript with static types -- with a host of tweaks including a way to explain why files are included in a project.

  • What's Top-Paying .NET Skill, In-Demand Language?

    New tech reports reveal the top-paying .NET skills and most in-demand programming languages in the Microsoft-centric developer landscape.

  • Microsoft's Distributed Application Runtime (Dapr) Debuts for Microservices

    Dapr is now production ready in version 1.0, easing microservices development on-premises, on the edge or in the cloud by abstracting away distributed computing hassles.

  • What's New in EF Core 6.0 Preview 1

    The Entity Framework Core 6 dev team shipped Preview 1 this week, headed toward a debut with the larger, unifying .NET 6 umbrella platform in November.

Upcoming Events