java – How to make music play in all activities]


It is necessary to make sure that the music continues to play during the transition to all activities. I use this code for sounds

 MediaPlayer mediaPlayer = new MediaPlayer();
    MediaPlayer click = MediaPlayer.create(this, R.raw."Нужная музыка");


The most primitive way is to make an instance of the class static, which is responsible for working with audio and working with it in any Activity. Here's an example of a simple music player I was making. This is, of course, a bad way, and in fact it is desirable to use Service for this purpose.

Scroll to Top