user836200
user836200

Reputation: 655

Timers within Android Services?

I have an Android Service that accesses the database about once per minute. Is there a way to, within this service, start another process within a timer that executes once every 12 hours? Right now I have the following code within my service but this code is executed at the same rate as the service:

UPDATE_INTERVAL = (1000*60)*60*12;
 timer.scheduleAtFixedRate(new TimerTask(){
                    @Override

                    public void run(){   

                        if(!parseDailyData(AppStatus.getConsumer(), AppStatus.getProvider(), client, dayData))
                        {
                            Log.v(TAG, "no parse day set");  
                        }
                        getTopPeople();
                    }

                }, 0, UPDATE_INTERVAL);

Upvotes: 0

Views: 233

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007554

I have an Android Service that accesses the database about once per minute.

Hopefully, this is only running while your application is in the foreground, or because the user explicitly asked for this service to run.

Is there a way to, within this service, start another process within a timer that executes once every 12 hours?

Use AlarmManager for something that will occur every 12 hours. You might even consider using it for something that will run every 1 minute, so you do not necessarily tie up memory all of the time.

Upvotes: 1

Related Questions