How can I start service from an adapter class in xmarine android c#?

soumenhaldersoumenhalder Member ✭✭
edited September 2018 in Xamarin.Android

How can I start service from an adapter class in xmarine android c#? I am trying the below mentioned code from my adapter class, but it gives me error.

var intent = new Intent(action);
intent.SetPackage("App1Test.App1Test");
StartService(intent);

Best Answer

Answers

  • BillyLiuBillyLiu Member, Xamarin Team Xamurai

    @soumenhalder

    What's the error do you meet?
    Could you post the full code? Please provide some more information.

  • @BillyLiu said:
    @soumenhalder

    What's the error do you meet?
    Could you post the full code? Please provide some more information.

    Hello @BillyLiu
    Please fine the below mentioned error snap

    this is the button click event which I called in Adapter class.


    This is the error which is coming from the methos of adapter while calling the service.

  • @BillyLiu said:
    @soumenhalder
    Are your SendAudioCommand() also in the adapter?
    If so you could try something like:

    Context context;
    public Adapter1(Context context)
    {
    this.context = context;
    }

    public void SendAudioCommand()
    {
    var intent = new Intent(context, typeof(MyService));
    intent.SetPackage("App1Test.App1Test");
    context.StartService(intent);
    }

    And please not post the screenshot as your code.

    @BillyLiu thank you for the support this is working fine.

Sign In or Register to comment.