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 is,I have declared finish() in onPause method in each activity(I don't want to let the user to return & want to kill the activity).
so when I intent to other activity it calls onDestroy and stops the service. I want to stop the service exactly exit the app( pressing the home button )and want to go through activities with BGM and finish() in onPause().is this possible? or is there another solution?
public class BackgroundMusicService extends Service {
private static final String TAG = null;
MediaPlayer player;
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
player = MediaPlayer.create(this, R.raw.topbgm);
player.setLooping(true); // Set looping
player.setVolume(100, 100);
}
public int onStartCommand(Intent intent, int flags, int startId) {
player.start();
return 1;
}
public void onStart(Intent intent, int startId) {
// TO DO
}
public IBinder onUnBind(Intent arg0) {
// TO DO Auto-generated method
return null;
}
public void onStop() {
}
public void onPause() {
}
@Override
public void onDestroy() {
player.stop();
player.release();
Log.i("service", "service killed");
}
@Override
public void onLowMemory() {
}
}
in manifest
<service android:name=".BackgroundMusicService" android:process=":remote" />