E
E
emigrantdd2014-10-20 23:22:13
Java
emigrantdd, 2014-10-20 23:22:13

How to change the service start interval?

Good day. The task is to change the interval through which the service starts (wakes up) (well, or rather the OnRecive method) during an already running service, roughly speaking, what would it change its interval within itself?
Now the interval is set before starting the service and it lies in the INTERVAl variable, and in the code it looks like this:

Intent intent = new Intent(this, RepeatingAlarmService.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(this, REQUEST_CODE, intent, 0);
        alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManager.setRepeating(
                AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + FIRST_RUN,
                INTERVAL,
                pendingIntent);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sultanov, 2014-10-21
@sultanov

Through a global variable.... for example... and assign as much as you want to it inside the method...

D
Dmitry, 2015-08-31
@falcon_sapsan

Can you be more specific?
I store the service start period in the application base.
How to apply the new settings?
Service.java

alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarmManager.setRepeating(
                AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime(),
                DB.getServiceRepeatTime(), // тут берется время
                pendingIntent);

setting a new value in the database does not affect the period when the service starts executing tasks.
How to apply the new value?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question