I want to run alarm service for every second in my application.It is working fine below 5.1 version. but it is not triggering in 5.1 devices. I am using commonsware wa
This is normal behavior in Android Lollipop.
Suspiciously short interval 1000 millis; expanding to 60 seconds
Tells you that the system does not like those short time intervals anymore.
Issue #161244 documented that:
This is working as intended, though is at present inadequately documented (and we're aware of that side of the problem).
Speaking very generally: short-period and near-future alarms are startlingly costly in battery; apps that require short-period or near-future work should use other mechanisms to schedule their activity.
So don't use an AlarmService
for this. Prefer a thread or Executors
or TimerTask
or something else:
// Using Handler
new Handler().postDelayed(runnable, TimeUnit.SECONDS.toMillis(1));
// Using Executors
Executors.newSingleThreadScheduledExecutor().schedule(runnable, 1, TimeUnit.SECONDS);