Cheok Yan Cheng
Cheok Yan Cheng

Reputation: 42710

Use LocalService or AlarmManager for a repeating and time consuming task

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

  1. If I am using 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.
  2. Can 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

Answers (1)

sujith
sujith

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

Related Questions