I have one activity and one service. My requirement is to start service from activity and in activity countdown timer will start, but problem is that I'm unable to get value from service to my activity. Please help me out.
Is any code,tutorial,example which will help me for this.
TIMER SERVICE
public class TimerService extends Service {
MyCounter timer;
@Override
public void onCreate() {
timer = new MyCounter(1 * 60 * 1000, 1000);
super.onCreate();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
timer.start();
return super.onStartCommand(intent, flags, startId);
}
private class MyCounter extends CountDownTimer {
public MyCounter(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
Toast.makeText(getApplicationContext(), "death", Toast.LENGTH_LONG)
.show();
stopSelf();
}
@Override
public void onTick(long millisUntilFinished) {
Toast.makeText(getApplicationContext(),
(millisUntilFinished / 1000) + "", Toast.LENGTH_SHORT)
.show();
}
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
timer.cancel();
super.onDestroy();
}
@Override
public IBinder onBind(Intent arg0) {
return null;
}
}
what should i write in this service so i will get toast message value in my activity