开发者

How to stop service after AsyncTask finished?

I have a service, that requests another class, which launches an AsyncTask

Service->Weather Class->Execute Method->Asynctask->Execute

this is launched in the service by

new Weather(this).execute(); // the execute is a method of the class, not of the A开发者_运维知识库syncTask

how do I detect in Service that the AsyncTask finished so I can call stopSelf?


You can use stopService(intent) in this case.


The approach currently employed in our application is to register a single BroadcastReceiver against the android.app.Service which is set-up to listen for broadcast events fired from the spawned underlying AsyncTask#onPostExecute. This is favourable in our scenario since our service spawns three AsyncTasks and we would like to stop the parent service when all three AsyncTasks have completed, i.e. we have three hits against our service level BroadcastReceiver.

Thought I'd add this here after I stumbled upon this question long after it was answered but hopefully it may help someone else...

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜