I implemented a Volley Request interval to fire a request periodically:
final Handler handler = new Handler();
final int interval = 3000;
handler.postDelayed(new Runnable() {
public void run() {
// Volley request here...
Volleyclient client = Volleyclient.getInstance();
client.doSomeVolleyRequest(MainActivity.this, someListener, someDataToSend);
handler.postDelayed(this, interval);
}
}, interval);
It works fine as long as the app is in foreground. If i push the home Button and the app goes asleep i got a Volley TimeoutError and I cannot figure out why. Same behaviour if i switch to "standby" mode (screen off). As soon as i toggle my app back to foreground it continues the volley requests.
I suspect it isnt really a timeout but an internet connection permission issue while falling asleep. I use the following permisions:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
Is anybody out there who is able to explain the reason for that behaviour? It would be nice if you can show me a workaround to make my app continue sending requests whenever the app is running.