i am developing an android app, where my class extends ContentObserver.I am registering my class for observing the changes in VOLUME_RING.
the onchange method of my class gets called only upon volume button changes.
The problem is, an global int variable which is getting updated in the constructor of the class is not getting updates in onchange method.
The code below is what i have tried,
public class VolumeChecker extends ContentObserver
{
Context context;
Handler handler;
int initialVolume;
public VolumeChecker(Context c, Handler handler)
{
super(handler);
context=c;
this.handler = handler;
AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
initialVolume = audio.getStreamVolume(AudioManager.STREAM_RING);
Log.e("inisde","volvhevker - intitvol " + initialVolume);
}
@Override
public boolean deliverSelfNotifications()
{
return super.deliverSelfNotifications();
}
@Override
public void onChange(boolean selfChange)
{
super.onChange(selfChange);
Log.e("onchange","initialVolume" + initialVolume);
refresh();
}
public void refresh()
{
new VolumeChecker(context,handler);
}
}
The initialVolume variable value, which is getting updated in the constructor upon refresh, is not getting reflected in the onchange method.
Please help.thanks!