views:

43

answers:

2

Hello all,

I am developing an application on Android Froyo system, everything is fine, except that when I create a service, and the service will spawn several thread. In one of the thread, I want to stop the service. Apparently stopService() is out of scope in the thread class, and so is the getApplicationContext() calls. So inside a thread, can I get the current context and how?

Thanks

A: 

Declare your own context

private Context mContext;

and use insted of getApplicationContext()

Jorgesys
+1  A: 

You can try MyService.this.stopSelf(). Or if that doesn't work, you can store a reference to your service when it's created. In your oncreate you can do Context ctx = this. And then in your thread ctx.stopSelf()

Falmarri