Are you sure you are stopping the same service?  You are passing something
different in for the Intent component.  I would suggest defining one static
Intent for the service, that is use for both start and stop.

On Mon, Jul 13, 2009 at 3:07 AM, Lex <[email protected]> wrote:

>
> Hi everyone,
>
> this message is in addition to the posts at
>
> http://groups.google.com/group/android-developers/browse_thread/thread/3f01a8576ebb0d7c/1a065e23513c1523
>
> I have a service receiving and sending data to a server in separate
> threads each. The service lifecycle methods look like this:
>
>        @Override
>        public void onCreate() {
>                super.onCreate();
>                receiver = new ReceiveThread(this);
>                myMapView.trafficMessages = new Vector<TrafficMessage>();
>
>        }
>
>        @Override
>        public void onStart(Intent intent, int startId) {
>                super.onStart(intent, startId);
>                receiver.start();
>        }
>
>        @Override
>        public void onDestroy() {
>                super.onDestroy();
>                receiver.kill(); // sets a boolean in the while loop to
> false so
> that run() finishes
>                heartbeat.kill(); // thread sending periodic messages to the
> server
> to keep the connection alive
>                stopSelf();
>
> The activity lifecycle methods look like this:
>
> @Override
>        public void onCreate(Bundle savedInstanceState) {
>                super.onCreate(savedInstanceState);
>                TAG = getString(R.string.application_name);
>                setContentView(R.layout.main);
>                context = getApplicationContext();
>
>                initMap();
>                initLocationManager();
>                ccClient = startService(new Intent(this,
> ClientService.class));
>        }
>
>        @Override
>        public void onPause() {
>                super.onPause();
>                locManager.removeUpdates(locListener);
>        }
>
>        @Override
>        public void onResume() {
>                super.onResume();
>
>  locManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
> 0, locListener);
>        }
>
>        @Override
>        public void onStop() {
>                super.onStop();
>                stopService(new Intent(this, cocarClient.getClass()));
>        }
>
> When I press the home button, the activity onStop() method is called
> but stopService() does not call the service onDestroy() method so the
> threads keep running in the background.
> Why doesn't the service shut down? What is the difference between the
> home and back button, what is activity-service lifecycle method call
> stack in these cases?
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to