Yossi wrote:
> Hi Mark,
> 
> My code is relatively simple
> 
> public void onResume()
> {
>       Intent intent = new Intent(this, TrackingService.class);
>       startService(intent);
>       bindService(intent, _connection, Context.BIND_AUTO_CREATE);
> }

Do either startService() or bindService(), not both.

> 
> public void onPause()
> {
>       if(shouldStopService())
>       {
>               unbindService(_connection);
>               stopService(new Intent(this, TrackingService.class));
>       }
> }

Do either unbindService() or stopService(), matching up with what you
chose to do in onResume().

Unless your service is in some other process (which the use of
TrackingService.class suggests it is not), you probably do not want to
use bindService()/unbindService(). Use startService() to start it, then
use stopService() only when you want to stop the service. Since it is in
your process, use other means (e.g., static singleton reference to the
service) to communicate with it from the activity.

Right now, your service stop shortly after your activity goes
off-screen, because you are telling the service to stop in onPause().

http://developer.android.com/reference/android/app/Service.html#ServiceLifecycle

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android 1.5 Programming Books: http://commonsware.com/books.html

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