문제

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?

도움이 되었습니까?

해결책

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
    }
  }
};

다른 팁

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 -

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top