我启动了一个IntentService。在onHandleIntent()方法中,我使用一个处理程序(Handler)发起了一个HTTP请求,并在请求完成时调用它,代码如下:
public function onHandleIntent(){
makeRequest("http://somehthing.com", new Handler(){
doStuff();
});
}
在HTTP请求返回之前,onHandleIntent()会立即完成。尽管请求确实返回了,但ServiceIntent线程已经被销毁,doStuff()永远不会运行。
如何处理类似于此的回调Handler结构以及ServiceIntent是最佳方式?