0

I have a service running in the background of an activity, now when the user presses the home button, onPause is called for the activity, what i want is to stop the service running in the background when onPause is called, but then i get an Error and a Force Close, Any ideas? Thank you!

mb567
  • 691
  • 6
  • 21
  • If your binding to the service, you'll get a nullpointer when you haven't connected. So check your binding for null before you attempt to stop it. – Blundell May 06 '12 at 18:25
  • *user1378365 - Last seen May 10 '12 at 3:28* pretty sure they do not care and it is a marker to others that dupes are bad m'kay ... –  Dec 11 '15 at 06:36

1 Answers1

2

Since we don't have any piece of code, I'm guessing the problem is you didn't recreate the intent that started the service before trying to stop it.

For example if you start the service this way:

Intent serviceIntent = new Intent(this, myService.class);
startService(serviceIntent);

You can stop it like this:

Intent serviceIntent = new Intent(this, myService.class);
stopService(serviceIntent);

Hope to have guessed well

BrainCrash
  • 12,992
  • 3
  • 32
  • 38