Issue
I start an IntentService. In onHandleIntent() I make an HTTP request with a Handler that is called when the request completes, like so:
public function onHandleIntent(){
makeRequest("http://somehthing.com", new Handler(){
doStuff();
});
}
onHandleIntent() finishes immediately, before the HTTP request returns. The request does return, but the ServiceIntent thread has already been destroyed and doStuff() doesn't ever run.
What is the best way to handle a callback Handler structure like this with a ServiceIntent?
Solution
Unfortunately, you don't. IntentService
is meant to queue off synchronous blocks of work, complete them in another thread, then finish. You'll have to create your own Service. You can take a look at the source code for IntentService
and start from there. Most importantly, you'll want to call stopSelf
after the callback is completed instead of after onHandleIntent
.
Answered By - kabuko
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.