When you start the same service again, it just has its onstart called:
nothing changes.  There's no such thing as a second service created,
there's only one of them in memory.

Additionally: I think everyone has mentioned that services run on the main
thread: how would one be running in the background and have another pop up.
 There's only one service, and as long as you send it messages it gets them.

If you instead mean that you're having `onStart` delayed until the other
one finishes, that's because it runs on the main thread.  By the way, you
shouldn't be doing anything in `onStart`, the same as how you shouldn't do
anything blocking in activities.  Again, you just *coordinate* threads
using your service.

Kris



On Thu, Aug 8, 2013 at 2:32 PM, ashish <ashish.a...@gmail.com> wrote:

> Hi,
> if one service is working in the background and we again start the service
> then onstart method for second time does not work until first one finish
> execution
>
>
> On Thursday, August 8, 2013 10:08:54 AM UTC-8, Streets Of Boston wrote:
>>
>> 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 <ashis...@gmail.com> 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 android-d...@googlegroups.com
>>>>> To unsubscribe from this group, send email to
>>>>> android-developers+**unsubscr...@googlegroups.com
>>>>> For more options, visit this group at
>>>>> http://groups.google.com/**group/android-developers?hl=en<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 android-developers+**unsubscr...@googlegroups.com.
>>>>> For more options, visit 
>>>>> https://groups.google.com/**groups/opt_out<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 android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> 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 android-developers+unsubscr...@googlegroups.com.
> 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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
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 android-developers+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to