Answer the question
In order to leave comments, you need to log in
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
Through a global variable.... for example... and assign as much as you want to it inside the method...
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);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question