Reputation: 42710
Currently, I have a stock market app. I would like to perform the following stock alert task code, even when my stock market app is being closed.
Perform a list of stock quotes retrieval, through HTTP network protocol every 30 minutes. Notify user through notification bar if certain stock hits price alert.
I was wondering, should I use
My concern is
LocalService
, let say the user kill the stock market app explicitly through Settings -> Apps -> Running -> Stop
, the service will be killed as well. The stock alert task code will no longer running.AlarmManager
ensure the stock alert task code will always executed even user kills the stock market app? However, is it suitable for AlarmManager
to execute such time consuming task?I was wondering, should I use LocalService
or AlarmManager
in my case?
Thanks.
Upvotes: 0
Views: 125
Reputation: 2421
I recommend you to use AlarmManager to send a pending intent to start the service for every 30mins. And the service does its job and calls stopSelf()
. Keeping service idle for very long time is waste of system resources.
Upvotes: 2