Reputation: 2196
I'm using loopj to post some data. It all works fine but I have some problems:
What is a good way to handle the case where no internet connection is available? At the moment I just retry after some time but like this, I have to store the data locally because if the user closes the app or even shuts down his device, the data won't be sent. Maybe it's the only way or do you know another way to do it?
When I post some data and the connection is bad, it sometimes just stopps. Does loopj have some kind of a timeout? How can you change that? And how can you know that it wasn't submitted?
I just need an extremely stable way to post data. Do you recommend to use another library than loopj?
Upvotes: 1
Views: 704
Reputation: 3019
A way to reliably transfer data:
From AsyncHttpClient class:
private static final int DEFAULT_MAX_CONNECTIONS = 10;
private static final int DEFAULT_SOCKET_TIMEOUT = 10 * 1000;
private static final int DEFAULT_MAX_RETRIES = 5;
private static final int DEFAULT_SOCKET_BUFFER_SIZE = 8192;
Upvotes: 1
Reputation: 6949
You can override onFailure() when it failed, and deal with the situation there.
@Override
public void onFailure(Throwable e) {
Log.d(TAG, e.toString());
}
And yes, there is timeout in AsyncHttpClient, 10 seconds by default. You can change it by setTimeout(int).
Upvotes: 0