What is the purpose of creating a new VolumeChecker
within refresh()
? You can simply update the variable again like so:
public void refresh() {
AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
initialVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
}
and perhaps do some refactoring to make audio a global variable so that you do not have to recreate it each time. You can likely refactor the contents of the refresh()
method directly into the onChange()
method as well.