I have the following class:
public class TimerTaskHelper {
private static TimerTaskHelper instance = null;
private static Integer ONE_MINUTE = 60000;
private static Handler handler;
private static Runnable runnableInstance;
private static Container container;
public static TimerTaskHelper getInstance(Container c) {
if (instance == null) {
instance = new TimerTaskHelper(c);
}
return instance;
}
public TimerTaskHelper(Container c) {
this.handler = new Handler();
this.runnableInstance = runnableCode;
this.container = c;
// Kick off the first runnableInstance task right away
handler.post(runnableCode);
}
// Define the task to be run here
private Runnable runnableCode = new Runnable() {
@Override
public void run() {
// Do something here on the main thread
Logger.d("Called");
// Repeat this runnableInstance code again every 2 seconds
handler.postDelayed(runnableCode, 2000);
container.notifyObservers();
}
};
public void stopExecution() {
handler.removeCallbacks(runnableInstance);
instance = null;
}
}
I'm able to get instance from controller using the:
mTimerTaskHelper = TimerTaskHelper.getInstance(container);
But i would like to get callback in controller after the each
private Runnable runnableCode = new Runnable() {
@Override
public void run() {
and
public void stopExecution() {
handler.removeCallbacks(runnableInstance);
instance = null;
}
From controller.
How can i do it in the best way please?