minhaz
minhaz

Reputation: 4233

starting a service in Android

I know that the best to start service is

startService(new Intent(this, MyService.class  ));

How can I send my application context also when I am starting a new service?

Upvotes: 0

Views: 353

Answers (3)

minhaz
minhaz

Reputation: 4233

Thanks guys i able to solve my problem by this line from my service

this.context=this.createPackageContext("com.myPackage", Context.CONTEXT_IGNORE_SECURITY );

Thanks for all those suggestion though.

/minhaz

Upvotes: 1

andy_spoo
andy_spoo

Reputation: 316

You could use:-

Context mycontext;
mycontext = getBaseContext();
startService(new Intent(mycontext, MyService.class  ));

Long winded code, but easy to understand, if this is what your looking for?

Upvotes: 0

Pentium10
Pentium10

Reputation: 207830

Why do you want to do that?

A Service itself is a context, use this when you need a context in a Service.

Upvotes: 1

Related Questions