6

I have an application in which i am generating a lot of notifications from a service.For each notification i have pending intent.Also pressing the home button stops my entire application and service using the following code

System.exit(0);

Firing the pending intent succeeds, but after pressing the home button if i am relaunching the app again it gives just a black screen and exits..Interesting thing is that if i click the app icon again it relaunch successfully..If the activity starts not using the pending intent, pressing the home button and relaunching everything works fine..

What should be the reason ? Any help will be greatly appreciated ..

hacker
  • 8,919
  • 12
  • 62
  • 108

1 Answers1

0

Is your service is not supposed to outlive your activity, you may not need the service at all. From your description, it looks like you can do everything directly from the activity.

Consider AsyncTask if you need some concurrency.

If the service is still the best option for you, then you should use Context.stopService() instead of System.exit() and clean up your background threads/notifications in the service's onDestroy().

full.stack.ex
  • 1,747
  • 2
  • 11
  • 13