1

I have a bound service playing sounds with Soundpool. It works normally if the app exits normally (using back button).

However, when the app is killed by the recent app, in the next run, the service (sound) behaves abnormally, especially, when the screen is OFF.

In detail:

  1. When the app starts after being killed by the recent app, I still can play the sound normally when the screen is ON.
  2. When the screen is OFF, the sound plays OK in next few seconds and then start to flicker. However, the symptom disappears when the screen turned back on.

I tested with Android N. And the code is nothing special, just like this link from Android developer website.

I don't know what is the differences between normal exit and app killed by recent apps.

How to properly stop the bound service if the app is removed from recent apps. Any help?

Thanks

T D Nguyen
  • 7,054
  • 4
  • 51
  • 71
  • What do you mean by _'service that binds to an activity'_? There is no way to "bind to an `Activity`. Please explain how these components are bound together. – David Wasser Jun 14 '16 at 09:32
  • I mean the bound service https://developer.android.com/guide/components/bound-services.html – T D Nguyen Jun 14 '16 at 09:46
  • Describe what you mean by "behaves abnormally". What do you expect to happen and what actually happens (or doesn't happen). We aren't mind readers here. – David Wasser Jun 14 '16 at 11:45
  • Thanks, I updated the question, hopefully, it is easier to understand. – T D Nguyen Jun 14 '16 at 12:07
  • You write _"the code is nothing special, just like this link from Android developer website"_. However, the linked article includes nothing about bound `Services`. Please post the code from your `onBind()` and `onUnbind()` methods and any other relevant methods. – David Wasser Jun 14 '16 at 19:01

1 Answers1

0

Killing from recent apps may be the same as force stop on some devices so no onPause or onStop is called on the activity in this case, so the service is probably not being unbound correctly.

If your service is not bound to a running activity and doesn't run in the foreground, the system may stop it at any time.

Sir Codesalot
  • 7,045
  • 2
  • 50
  • 56