0
I am developing an application in JAVA, Android Studio, and I need to make some JSON requests.
So I created an Asynctask class and do so in theInBackground:
@Override
protected String doInBackground(String... strings) {
String command = strings[0];
String json;
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(command);
request.addHeader("Authorization", "Basic c3VwZXI6MTIzNA==");
try {
HttpResponse response = client.execute(request);
...
The problem occurs when the server does not respond, whether it is off or slow even....
How can I do?
I suggest you retrofit instead of Asynctask, here you can find how to change the retrofit request time. hope to have helped
– Walter Felipe
However, if not the ideal resolution. there is a duplicate of your question in the official community Android Setting a timeout for an Asynctask
– Walter Felipe