I\'m creating a game application with background music.I used Android Service to play the background music because I wanted to run BGM while changing activities. my problem
stopService(new Intent(this, BackgroundMusicService.class));
add this to your onPause()
method and onDestroy()
method in your main activity. Because If you press the Home
button the app will be on background for random time and onDestroy()
method would not invoked as soon as you minimize the app. The best way to do it is putting it in to the onPause()
method. onPause()
method is invoked when your application activity is not the fore-ground activity.
put this line in yout activity
stopService(new Intent(this, BackgroundMusicService.class));
in onDestroy() method where you pressing the home button.
Override the method onUnbind(Intent intenet) in Service