Timer in background

I need to run a timer in the background for all activities. Sometimes the timer will start a new activity briefly. Then the user can close that new activity. What is the simplest way to do this? If I start the timer on the first activity will it run through all other activities? I'd rather not use a separate service. If a service is the best way, can I create the service inside my current app? I don't want it to run outside my app. Thanks!


  • TomOpgenorthTomOpgenorth CAXamarin Team Xamurai

    Odds are that you should use a service - just in case Android decides to kill your Activity while it's in the background. Yes, you can create a service that is only for your app, you don't have to create a new app just for the timer. Linking the docs on Creating Services to help you get started. :)

  • MatthewHoltzMatthewHoltz USMember

    Thanks for the info. I've went over the services link, but it is for a separate service. Do you know of any examples about creating a service inside of an existing app?

  • MatthewHoltzMatthewHoltz USMember

    I got it to work. Just added this inside my namespace, but before my activity:

    [Service] public class SimpleService : Service {all my stuff here... }
    Thanks again for the help!

Sign In or Register to comment.