0

I am designing an app that has weather info to display at home screen. I want to update weather every 10 minutes.

I have a issue to update UI when home activity is in background (another activity is open upon home activity)

some help but issue in updating UI: Scheduling recurring task in Android

Please advice me if another way to do this. Thanks in advance.

Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50

2 Answers2

0

Use AlarmManager:

  1. Periodically executing background tasks
  2. Executes even if application is not running
  3. Used when long running task is not required forever
  4. For most cases, setup a Scheduler that triggers a background service at regular intervals

Suggestion: Use IntentService in conjunction with the AlarmManager

Reference & link: AlarmManager - CodePath

Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50
0

I have gone through your question and I am glad to give you the appropriate answer based on my personal experience. Well if you are interested in gathering the weather updates every 10 minutes even when the application is in background, then I suggest you to use Background Service. You can't imagine the advantages of background service. There are three kinds of background service

  1. Started Service
  2. Intent Service
  3. Bound Service

All of the above three has there own usages. But in your case i suggest you to use the Started service. This service will start when you will call the startService() method, and will stop when you will call the stopService() method. Using the background service over Alarm Manager is recommended, and implementation is also quite simple and you can go through this link to understand the background service.This service will also keep on running in background even when your app is in background and will also gather the weather data every 10 minutes.

Pranay Soni
  • 403
  • 3
  • 12