Re: [android-developers] What is the use of services in Android?

2013-08-09 Thread Daniele Segato
Hi, It is Upon to you to decide if you want to do startService() or bindService() The meaning of startService is: wake up the service (create it if doesn't exist) and give it this command. The service should know what's doing and, if the command is already running should just discard the

Re: [android-developers] What is the use of services in Android?

2013-08-09 Thread Daniele Segato
Hi, I think you should tell to us what you are trying to do cause repeating that you do startService the second time and it does not work doesn't mean a thing if we don't know what you want to do and what your service does. Regards, Daniele Segato On 08/08/2013 08:32 PM, ashish wrote: Hi,

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread Kristopher Micinski
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

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread Daniele Segato
On 08/08/2013 01:40 PM, ashish 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

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread ashish
Hi, suppose an activity start a background service in the oncreate method and now user switch to other activity and when my app is working in the background then system kill my activity life-cycle but when i return to my activity then system call the oncreate method of my application and then

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread ashish
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

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread Kristopher Micinski
That's not how it works, you're misunderstanding services. That's what happens if you use a thread, so in fact you're exactly switching the meaning of a service. First of all, the service won't have it's `onStart` executed until your oncreate returns anyway, since it just pushes messages onto

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread Streets Of Boston
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

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread Kristopher Micinski
You send a message to the service to stop the thread. Then the service stops the thread, by setting some flag or condition variable. Kris On Thu, Aug 8, 2013 at 2:04 PM, ashish ashish.a...@gmail.com wrote: Hi, if a service starts a new thread then how i can stop the service from the

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread ashish
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

Re: [android-developers] What is the use of services in Android?

2013-08-08 Thread Kristopher Micinski
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