Re: [android-developers] What is the use of services in Android?
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 new request (or whatever logic fit your app). BindService say: give me a binder object to the service so that I can ask it directly for information. Usually you send command with startService() and then forgot you asked for them. If you want to know the state of a Service instead you bind to it. A good practice I use when I have to show the state of some operation going on in background is binding to a service in the activity onCreate() and unbinding in onDestroy(). I define my service with a binder interface to let binded activities ask for informations about the state of the service (how many task are running, how many are pending, the progress of each one for example) and when I need (or when the user ask) I start a command with startService(). I develop the service so that it know what it is doing (which threads are running and doing what) so I know when to call stopSelf() when no more threads / operations are running. I think Google Play app is doing something similar when showing if you are installing / upgrading an application. This works very well because even if your activity die, is rotated or you need to know what's going on from different activities you just have to bind to it and ask. Said so if you need to sync data remotely when opening your activity you should be using SyncAdapters http://developer.android.com/training/sync-adapters/index.html Regards, Daniele Segato On 08/08/2013 08:02 PM, ashish wrote: 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 android system again start a new service again even the last one working in the background.. On Thursday, August 8, 2013 4:53:27 AM UTC-8, Daniele Segato wrote: 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 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've been already told by others that Services should be used to MANAGE separate thread(s). The important part is that while an application is used to interact with the user a Service has no UI and can run in background. And with background I don't necessary mean off-the-main-thread. I mean that they can run even if the application (activities) is not used at the time. Services have a simpler life cycle in respect to activities and they are not influenced or killed by the framework by changes in configurations. Furthermore the framework will kill activities before starting to kill services. And if the framework decide to kill your service you can specify what you want to do with the request you received (drop it, ask the framework to re-do it, etc...) Services are a main component of the system and it is good practice to, for example, use them to update underling data (better if using a SyncAdapter) and manage remote calls. regards, Daniele Segato -- 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,
Re: [android-developers] What is the use of services in Android?
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, 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.
[android-developers] What is the use of services in Android?
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-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.
Re: [android-developers] What is the use of services in Android?
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 ashish.a...@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-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.
Re: [android-developers] What is the use of services in Android?
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 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've been already told by others that Services should be used to MANAGE separate thread(s). The important part is that while an application is used to interact with the user a Service has no UI and can run in background. And with background I don't necessary mean off-the-main-thread. I mean that they can run even if the application (activities) is not used at the time. Services have a simpler life cycle in respect to activities and they are not influenced or killed by the framework by changes in configurations. Furthermore the framework will kill activities before starting to kill services. And if the framework decide to kill your service you can specify what you want to do with the request you received (drop it, ask the framework to re-do it, etc...) Services are a main component of the system and it is good practice to, for example, use them to update underling data (better if using a SyncAdapter) and manage remote calls. regards, Daniele Segato -- 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.
Re: [android-developers] What is the use of services in Android?
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 android system again start a new service again even the last one working in the background.. On Thursday, August 8, 2013 4:53:27 AM UTC-8, Daniele Segato wrote: 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 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've been already told by others that Services should be used to MANAGE separate thread(s). The important part is that while an application is used to interact with the user a Service has no UI and can run in background. And with background I don't necessary mean off-the-main-thread. I mean that they can run even if the application (activities) is not used at the time. Services have a simpler life cycle in respect to activities and they are not influenced or killed by the framework by changes in configurations. Furthermore the framework will kill activities before starting to kill services. And if the framework decide to kill your service you can specify what you want to do with the request you received (drop it, ask the framework to re-do it, etc...) Services are a main component of the system and it is good practice to, for example, use them to update underling data (better if using a SyncAdapter) and manage remote calls. regards, Daniele Segato -- 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.
Re: [android-developers] What is the use of services in Android?
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 javascript: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.comjavascript: To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com javascript: 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 javascript:. 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.
Re: [android-developers] What is the use of services in Android?
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 the looper. Then the service will be started, but if it's already doing work, just recognize that by keeping some sort of state inside your service. Kris On Thu, Aug 8, 2013 at 2:02 PM, ashish ashish.a...@gmail.com wrote: 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 android system again start a new service again even the last one working in the background.. On Thursday, August 8, 2013 4:53:27 AM UTC-8, Daniele Segato wrote: 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 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've been already told by others that Services should be used to MANAGE separate thread(s). The important part is that while an application is used to interact with the user a Service has no UI and can run in background. And with background I don't necessary mean off-the-main-thread. I mean that they can run even if the application (activities) is not used at the time. Services have a simpler life cycle in respect to activities and they are not influenced or killed by the framework by changes in configurations. Furthermore the framework will kill activities before starting to kill services. And if the framework decide to kill your service you can specify what you want to do with the request you received (drop it, ask the framework to re-do it, etc...) Services are a main component of the system and it is good practice to, for example, use them to update underling data (better if using a SyncAdapter) and manage remote calls. regards, Daniele Segato -- 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.
Re: [android-developers] What is the use of services in Android?
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 --- 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.
Re: [android-developers] What is the use of services in Android?
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 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=enhttp://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_outhttps://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.
Re: [android-developers] What is the use of services in Android?
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 --- 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.
Re: [android-developers] What is the use of services in Android?
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=enhttp://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_outhttps://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.