2

For making my example handy, you can picture the default Android Alarm Clock. This is how me a beginner would solve it. This happens in the activity that gets called by BroadcastReceiver when the alarm needs to start.

    Ringtone ringtone;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Uri alarmTone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM);
        ringtone = RingtoneManager.getRingtone(getApplicationContext(), alarmTone);
        ringtone.play();
    }

    @Override
    public void onUserLeaveHint() {
        super.onUserLeaveHint();
        ringtone.stop();
    }

What is the difference (advantage/disadvantage in this example) between using RingtoneManagerin a service or an activity?

Any suggestion is welcome :)

Thomas R
  • 21
  • 3

0 Answers0