I am looking for a way to send data from my timer task to service. I have seen many other post related to handlers and all but I do not want to run in my main thread
Asked
Active
Viewed 501 times
-1
-
what is the task you are doing? – Pankaj Kumar Jan 02 '13 at 16:06
-
understand your problem first and then post question here with all needed details. – dd619 Jan 02 '13 at 16:12
-
I have a background service running always and updates are scheduled periodically. I have a timer task which connects to the server and gets the server time and then I need to pass that servertime from that timer task to my service. – user1810931 Jan 02 '13 at 16:45
1 Answers
1
you can write a singleton class which will hold data which you want to share. This is just a way not standard.
TimerTask task = new TimerTask() {
public void run() {
if (condition) {
MySingleton.getInstance().setData(put data here);
} else {
timer.cancel();
}
}
};
Timer timer = new Timer();
timer.schedule(task, 1000, 1000);
//then cancel timer somewhere by
timer.cancel();
then in service you can get data by some thing like this
DataType myData = MySingleton.getInstance().getData();

Farooq
- 426
- 2
- 12