Send another Intent (different action) to the IntentService. Override the 
onStartCommand to catch this Intent and this could allow you to 
stop/interrupt the ongoing process in the IntentService's background thread.

On Thursday, August 8, 2013 2:04:33 PM UTC-4, ashish wrote:
>
> Hi,
>
> if a service starts a  new thread then how i can stop the service from the 
> other class.
>
> On Thursday, August 8, 2013 3:51:19 AM UTC-8, Kristopher Micinski wrote:
>>
>> Usually you use a service to coordinate a thread.
>>
>> FYI most of the time you don't want to outright kill a thread (e.g., if 
>> it's about to return from a download operation), you want to periodically 
>> check a flag.
>>
>> You probably don't want to use threads in their raw fashion (from 
>> activities) for a few reasons, one of which being that with configuration 
>> changes they're trickier to get right.  Instead if you need background work 
>> that fits the model, an AsyncTask is an appropriate design.
>>
>> Kris
>>
>>
>> On Thu, Aug 8, 2013 at 7:40 AM, ashish <[email protected]> wrote:
>>
>>> I read about services in Android very carefully, but I didn't find any 
>>> valid reasons to use it. E.g.
>>>
>>>    1. 
>>>    
>>>    By default services run in the main thread, which most of the 
>>>    applications don't want.
>>>    2. 
>>>    
>>>    A service can run on a seperate thread if it spawns it own thread. 
>>>    But if a service runs on a seprate thread, then the method 
>>> stopService(new 
>>>    Intent(getApplicationContext(), MyService.class)); does not stop the 
>>>    running service. Again this is a problem.
>>>    
>>> If we want to do some background operations, then I think threads are 
>>> better than services. Am I right?
>>>  
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Android Developers" group.
>>> To post to this group, send email to [email protected]
>>> To unsubscribe from this group, send email to
>>> [email protected]
>>> For more options, visit this group at
>>> http://groups.google.com/group/android-developers?hl=en
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Android Developers" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to [email protected].
>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>  
>>>  
>>>
>>
>>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to