Android Question Play continuous music when changing activities

hatzisn

Expert
Licensed User
Longtime User
Hi everybody,

I am trying to implement a solution that would start playing some music when it downloads something and proceed in 5 seconds in the next activity automatically (the music lasts about 20 seconds). Here is what is happening:

I am trying to play the music with the with MediaPlayer object. Sometimes the music starts and continues playing when changing to the second activity and sometimes stops immediately when I call the StartActivity method. I tried moving the playing of the music to a service and make the service play it in the Service_Start method. I tried it but the same thing happens again. What is the meaning of all this? Why does Android decide by itself what to do (play continuesly or stop immediately the music)? Is there any way to manipulate this? I tried it in Android 7.

Thanks
 

Semen Matusovskiy

Well-Known Member
Licensed User
To place in service is Ok. The attached sample continious to play, when you switch activities. And more - it plays even in background
 

Attachments

  • zip.zip
    12.6 KB · Views: 265
Upvote 0
Top