Vra

in the beginning I thought it would be fairly simple, but I guess it's not. I want to call a URL every 10 minutes, either when the app is in the background or in the foreground. How can I realize this?

Was dit nuttig?

Oplossing

I'd use a Service with a Handler inside. Using directly Threads is another approach but it's more likely it will be killed if the Android OS needs to free memory.

The Handler part would be something like this:

boolean stopHandler = false;

Runnable runnable = new Runnable() {
  @Override
  public void run() {
    // Do whatever you need
    ...

    if (!stopHandler) {
      handler.postDelayed(this, 600000);     // 10 minutes
    }
  }
};

Ander wenke

In iOS 7 you can schedule background operations for periodically fetching data from the network. This tutorial is an example of scheduling background fetch operations -

Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow
scroll top