0

I am having trouble finding the best way to activate an alarm tone. My broadcast receiver is called, the media player starts, but then stops. after about a second when my alarm app is closed and not open in recent apps. It will play continuously if the alarm app is open. Does anyone know the best way to play a sound once an alarm broadcast receiver goes off?

auotive
  • 179
  • 1
  • 9
  • You should share your code how you are using broadcast receiver. If you are registering and unregistering receiver in activity then it will not work when app is closed. – Keyur Nimavat Jul 22 '22 at 05:44
  • I have put in the broadcast receiver. Please let me know if you see anything. Thank you. – auotive Jul 22 '22 at 23:15

1 Answers1

0

I found out what it was. It was apparently because my media player was getting destroyed by the garbage collector. So this answer https://stackoverflow.com/a/7719296/14727778 pointed out to use the media player as class level variable instead of declaring it in a method, so it does not get swept away. Pretty obvious! howd I miss that.....

auotive
  • 179
  • 1
  • 9