开发者

starting a service in Android

开发者 https://www.devze.com 2023-01-06 19:47 出处:网络
I know that the best to start service is 开发者_运维知识库 startService(new Intent(this, MyService.class));

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?


Why do you want to do that?

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


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


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?

0

精彩评论

暂无评论...
验证码 换一张
取 消