android - What drains the battery more: A longliving Service that does not do much or a many shortlived IntentServices -
i designing application collect different data lot of sensors , store them in db, continuously. sensors using google play's fused location provider , activity detection. (there ui well, ui barely launched, happening in background)
i got 2 different ways this:
1) start longliving service
so start long-living service (with sticky flag), run in background. service register periodic location , activity updates , - in between updates - nothing.
pros: app initialized once
cons: service running 24x7
2) register pendingintent , use shortlived intentservice
now google play's location provider support registration of pendingintent instead of callback [see here](https://developers.google.com/android/reference/com/google/android/gms/location/fusedlocationproviderapi#requestlocationupdates(com.google.android.gms.common.api.googleapiclient%2c%20com.google.android.gms.location.locationrequest%2c%20android.app.pendingintent) recommended background tasks.
pros: app can 'shut down' between sensor events
cons: each intentservice might re-start app if shut down inbetween, has quite overhead (initialize db, read shared prefs, initialize classes, ...)
so question is: is still recommended use many short lived intentservices kind of app? haven't done measurements yet, worried, each intentservice (and launched quite often), re-starts app, end spending more cpu time on initialization, etc. having long-lived service lying dormant.
anybody has experience this?
Comments
Post a Comment