When I created the thread in the Service itself, it worked. Thank you very much!
On Oct 12, 12:37 pm, Dianne Hackborn <hack...@android.com> wrote: > I don't see you creating a service anywhere in your code service, so I'm not > sure what you mean about creating one and not having it run... yes, if you > don't create one for your service there won't be one for it to run. :} > > You need to make a thread in your service -- either in onCreate() or > onStart() -- in which to do your work, and quit the thread at the > appropriate time when done. > > Or you really may want to consider just using IntentService to let it take > care of this for you: > > http://developer.android.com/reference/android/app/IntentService.html > > > > On Mon, Oct 12, 2009 at 11:19 AM, abhi <rkabhi1...@gmail.com> wrote: > > > I created a new thread and tried starting the service from there, but > > the service is not being started from the new thread. When I set a > > break point in the new thread, it does not hit and there is nothing > > updated on logcat. Any ideas as to why this is happening? > > > From my main class, I am creating a new thread and starting it: > > Thread th = new Thread(new ServiceStarter()); > > th.start(); > > > In the ServiceStarter, class I am creating the service and starting > > it: > > > class ServiceStarter extends Activity implements Runnable > > { > > > �...@override > > public void run() > > { > > try > > { > > Intent service = new Intent > > (ServiceStarter.this,Alarm.class); > > startService(service); > > > } > > catch(Exception ex) > > { > > ex.printStackTrace(); > > } > > } > > } > > > My service looks like this: > > > public class MyService extends Service > > { > > > �...@override > > public IBinder onBind(Intent intent) > > { > > return null; > > } > > > �...@override > > public void onCreate() > > { > > super.onCreate(); > > } > > > �...@override > > public void onStart(Intent intent, int startId) > > { > > boolean loopVar = true; > > > while(loopVar == true) > > { > > //Do stuff > > if(condition) > > { > > //Exit the loop > > loopVar = false; > > } > > } > > } > > } > > > On Oct 11, 12:54 pm, Dianne Hackborn <hack...@android.com> wrote: > > > Services don't take focus input focus -- a service doesn't cause the > > current > > > window to lose input focus, nor the foreground activity to be paused. > > > If you mean the thread of your activity isn't running, then you may just > > be > > > doing all your work in the service on the main thread. Please note that > > a > > > service's callbacks (but not necessarily calls through any IBinder > > interface > > > it publishes) happen on the main thread. If you want to run on another > > > thread, you'll need to make it yourself. > > > > On Sat, Oct 10, 2009 at 1:21 AM, abhi <rkabhi1...@gmail.com> wrote: > > > > > Hi, > > > > > I am starting a service from an activity. Once the services starts, > > > > the calling activity loses focus and blocks till the service is > > > > completed. Why is this and is there a way around it to return the > > > > control to the calling activity while the service runs in the > > > > background? > > > > > Thanks, > > > > -- > > > Dianne Hackborn > > > Android framework engineer > > > hack...@android.com > > > > Note: please don't send private questions to me, as I don't have time to > > > provide private support, and so won't reply to such e-mails. All such > > > questions should be posted on public forums, where I and others can see > > and > > > answer them. > > -- > Dianne Hackborn > Android framework engineer > hack...@android.com > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---