Question

I have a timer in my TimerService with a task. Every 5 seconds it has to call another Service.

@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);
        }

But i can't do it in a timer, how can i solve?

startService(new Intent(this, CameraService.class));
Était-ce utile?

La solution

Yes, but to get it to work you must set a proper context:

startService(new Intent(TimerService.this, CameraService.class));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top