Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Building Services in Android Using C# and Xamarin

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 152
    Comment on it

    In Xamarin we have functionality to build app using C# and other Visual Studio supportive languages.


    We can build apps by implementing services into it.


    For using and implementing services we can use interfaces and classes that contains the property and methods to invoke and handle user and system defined services.


    In android app we can do it by implementing interface named IBinder


    And we bind this service with the help of intent.


    System.Threading.Timer _timer;


    public override void OnStart (Android.Content.Intent intent, int startId)
    {
           base.OnStart (intent, startId);
    
           Log.Debug ("My Service", "SimpleService started");
    
    }
    
    public override void OnDestroy ()
    {
           base.OnDestroy ();
    
           _timer.Dispose ();
    
           Log.Debug ("My Service", "SimpleService stopped");
    }
    
    public void DoStuff ()
    {
           _timer = new System.Threading.Timer ((o) => {
                  Log.Debug ("SimpleService", "hello from simple service");
                  }, null, 0, 4000);
    }
    
    public override Android.OS.IBinder OnBind (Android.Content.Intent intent)
    {
           throw new NotImplementedException ();
    } 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: