0

Possible Duplicate:
Static Way to get Context on android?

I have a broadcast receiver class and service class and I am starting my service inside my broadcast receiver if I receive a string "testing".

THis is how I start my service inside my broadcast receiver class. It's working

private void startSMSforwarderService(Context context,String y)
{
    if(y.startsWith("testing"))
    {
        Intent SmsForwarderService = new Intent(context,SmsForwarderService.class);
        SmsForwarderService.putExtra("var_msgbody",msgbody); //pass variable value via intent from broadcast receiver to android service
        SmsForwarderService.putExtra("var_from", from);

        context.startService(SmsForwarderService);
    }
}

I have a method inside my service that needs context and I want to extend my context from my broadcast receiver to my service. How could I do that? Some snippet would much appreciated.. Thanks

my receiver https://gist.github.com/3171877

My service class

https://gist.github.com/3171792

As you can see I have a method inside my service and it needs a context before I can use that..

void forwardSMS(String msgbody,Context smsSenderService, Intent SENT_ACTION)

Basically I want to pass my broadcast receiver context to my service class....

Community
  • 1
  • 1
mboy
  • 744
  • 7
  • 17

1 Answers1

0

Problem solved.. I found this Static way to get 'Context' on Android?

but is their another way to do it?

Community
  • 1
  • 1
mboy
  • 744
  • 7
  • 17