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.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to