android - Using a Service to create a timer that runs even if the app is minimized? -
i seem have hard time getting straight answer on i'll make more pointed question.
i want create timer start/stop/pause/resettable. if timer active, should continue active if go somewhere else in app or minimize app. if app destroyed / shut down / closed altogether timer can shut down.
i looked alarmmanager doesn't seem work right on devices. service viable alternative / need do? use perform counting? sleep command in loop sends update command broadcastreceiver?
how send notification user when timer hits 0?
if app destroyed / shut down / closed altogether timer can shut down.
you seem think somehow different "go somewhere else in app or minimize app". not. either process running, or not, , process can terminated @ point in time when ui not in foreground. foreground service
, tied notification
, typical pattern keeping process around long possible, not absolute guarantee.
are implying on devices, no matter (service, timer, intentservice, alarmmanager, jobdispatcher, etc), kill timer because devices kill background tasks (unless misunderstood page)?
there 2 ways of doing scheduled work:
in-process:
timer
,scheduledexecutorservice
,postdelayed()
, etc.out-of-process:
alarmmanager
,jobscheduler
on android versions, when process terminated, in-process timing goes away too. how computers have worked, since invention of computer. hence, these sorts of scheduling options fine cases need work happen while process running (e.g., updating on-screen elapsed-time counter).
on android 6.0+, alarmmanager
, jobscheduler
affected doze mode , app standby. on previous versions, supposed reliable. however:
some device manufacturers created own doze mode equivalents, , manufacturers might wipe out alarms , jobs part of power-savings initiatives
nothing survives force-stop, happens if user clicks "force stop" on app's screen in settings, on devices happens more (e.g., manufacturer tied sort of built-in "task manager" have force-stop behavior)
hence, devices manufacturer screwed around android, there may not form of reliable scheduling mechanism. in cases, manufacturers implementing precursors doze mode offered whitelist mechanism, akin how doze mode on android 6.0+, users indicate apps prefer not impacted power-saving measures.
Comments
Post a Comment