I am creating a game application with background music. I used the Android service to play background music because I wanted to start BGM when changing actions. my problem is that I declared finish () in the onPause method in every action (I don't want the user to return and want to kill the action).
therefore, when I intend to use another activity, it calls onDestroy and stops the service. I want the service to completely leave the application (by clicking the "home" button), and you want to perform actions with BGM and complete () in onPause (). Is it 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);
in manifest
<service android:name=".BackgroundMusicService" android:process=":remote" />
java android
Hassy31
source share