Timer with callback
Info
Objective
public void do (){
timer.scheduleAtFixedRate (new TimerTask (){
public void run (){
storedInterface.A ();
}
}, 0, speed);
}
private void startCallback (){
runOnUiThread (new Runnable (){
public void run (){
storedInterface.A ();
}
});
}
public void do (){
timer.scheduleAtFixedRate (new TimerTask (){
public void run (){
startCallback ();
}
}, 0, speed);
}
Posible workaround
Extend SensorClass from an Activity but SensorClass is not an Activity with methods onCreate(), onPause(), etc!!! I don't like this solution.
My question is: How can I call runOnUIThread() within a class that only recieves a context from an Activity? Or... Is there any other solution for my problem?
Thanks.
Solved using handler. Great tool!
public void do (){
final Handler handler = new Handler ();
timer.scheduleAtFixedRate (new TimerTask (){
public void run (){
handler.post (new Runnable (){
public void run (){
storedInterface.A ();
}
});
}
}, 0, speed);
}
链接地址: http://www.djcxy.com/p/74936.html
上一篇: Android PagerAdapter destroyItem(),在使用片段时缓存一段时间
下一篇: 定时器与回调
