我的TimerService中有一个带有任务的计时器。每隔5秒就必须拨打另一个服务。
@Override
public void onCreate()
{
super.onCreate();
Log.i("ServiceDemo01", "Service Starts");
TimerTask task = new TimerTask()
{
@Override
public void run()
{
startService(new Intent(this, CameraService.class));
Log.i("ServiceDemo01", "Picture Taken");
}
};
timer = new Timer();
timer.schedule(task, 0, 5000);
}
但是我不能在计时器中做到这一点,我该如何解决?
startService(new Intent(this, CameraService.class));
答案 0 :(得分:4)
是的,但要使其发挥作用,您必须设置适当的背景:
startService(new Intent(TimerService.this, CameraService.class));