b= new TimerTask()
{
@Override
public void run()
{
out_string = hi.getWebPage("http://daniandroid.honor.es/getAllCustomers.php");
frum_timer = Integer.parseInt(out_string.replaceAll("[\\D]",""));
};
};
t.scheduleAtFixedRate(b, 500, 1000);
Every 1000 ms, run() will store the value to int frum_timer
I'm using this for an flashlight application. When I open the app, I want my app to switch on and off flashlights using frum_timer for interval time.
So if
frum_timer = 1000;
my flashlight will turn on and off every 1 sec. and if I edit to
frum_timer = 300;
it will turn on and off every 0.3 sec.
I tried instantiate a new TimerTask()
c=new TimerTask()
{
@Override
public void run()
{
timetask = new TimerTask()
{
boolean checking = false;
@Override
public void run()
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
if(checking==true)
{
//camera turning on
checking=false;
}else{
//camera turninf off
checking=true;
}
}
});
}
};
}
};
//some code
t.scheduleAtFixedRate(c, 50, 700);
but it's quite hard, because when I change the value, a new timer will start and the old one will remain active.
BTW: I know that the code for turning on/off will not change at the same interval as I want because of my amateur programmer skills (if checking...etc)