S
S
samarjan2014-11-10 15:43:30
Android
samarjan, 2014-11-10 15:43:30

How to make a request to the server in the best way?

I made a project in which I used a splash activity during which there were calls to the server, I did it with the help of Handler, which, if it failed, restarted itself with a certain timeout, I implemented the calls to the server using the AQuery library. The solution seemed to me not very successful, but since everything worked, I decided to leave it like that. My mistake was to leave a small timeout and leave requests to the server when the application went to the tray, and the server did not respond and there were constant requests, and as a result of all this, after the application was advertised, the server crashed (the application crashed it). I redid the logic, I read in the AQuery documentation that it is possible to interrupt the execution of the thread until a response arrives (before that, I just sent a request and looked through the timeout whether it came or not), but this solution didn't work in Handler and had to use Thread. The convenience of stopping the thread when it goes to the tray has disappeared (before that, I called Handler.removeCallbacksAndMessages(null) in the onStop method), and now I use a boolean variable that determines whether it is worth continuing to execute requests to the server in the Thread itself.
It is very interesting, how else are requests to the server implemented when the application is launched (your experience is interesting)? Or maybe I'm doing it wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yurevich1, 2014-11-10
@Yurevich1

You can make a thread with a while(!(!Thread.currentThread().isInterrupted())){}
loop and interrupt through thread.interrupt().
Alternatively, you can send requests both stupidly through the usual methods ( java.net.HttpURLConnection) , and using libraries, for example, jsoup.org

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question