You have declared it locally to that method
cheduleTaskExecutor.scheduleAtFixedRate(new Runnable() {
public void run() {
float x = (float) Math.random();
if (x <0.5){
float targetVolume =0;}
declare it as a member variable to the class to have class scope. This means to define it anywhere outside of a method (usually just before onCreate()
for an Activity
).