How to stop Service when app is paused or destroyed but not when it switches to a new Activity?
问题 Currently I have a Service which I am using to play a sound file in the background whilst the app is open: public class BackgroundSoundService extends Service { MediaPlayer player; public IBinder onBind(Intent arg0) { return null; } @Override public void onCreate() { super.onCreate(); player = MediaPlayer.create(this, R.raw.sound); player.setLooping(true); player.setVolume(100, 100); } public int onStartCommand(Intent intent, int flags, int startId) { player.start(); return 1; } @Override