-1

I have an android app that loads, some data from the web and before I do this I check if the user has internet connection,

Now if there is no internet connection I want to try and load the data again, after a few seconds?

How can this be down, is there a simple way to achieve this?

iqueqiorio
  • 1,149
  • 2
  • 35
  • 78

1 Answers1

0

There are two ways of doing this one is using a Broadcast Receiver that listen to android.net.conn.CONNECTIVITY_CHANGE and the other is using an Alarm Manager.... Using Broadcast receiver is advisable because it is more efficient .Here is a small example that u could look out this link

Alarms (based on the AlarmManager class) give you a way to perform time-based operations outside the lifetime of your application. For example, you could use an alarm to initiate a long-running operation, such as starting a service once a day to download a weather forecast.

Alarms have these characteristics:

  • They let you fire Intents at set times and/or intervals.
  • You can use them in conjunction with broadcast receivers to start services and perform other operations.
  • They operate outside of your application, so you can use them to trigger events or actions even when your app is not running, and even if the device itself is asleep.
  • They help you to minimize your app's resource requirements. You can schedule operations without relying on timers or continuously running background services.

This link will give u a basic example of how to use arm manager class

Community
  • 1
  • 1
Gowtham Raj
  • 2,915
  • 1
  • 24
  • 38