SoFunction
Updated on 2025-04-07

How to keep conversation under Volley framework in Android

The company manager pulled me out and tried to make an Android app. As a novice who has just graduated for a few months and has only been training for a few months, this is undoubtedly a very big challenge. Of course, the biggest challenge is not this. The biggest challenge is done in two weeks. To be honest, for those with two or three years of development experience, it is very simple to develop a project in two weeks, and maybe there is still a lot of time to do something else.

So I was stumped as soon as I came up. Login was easy to do. I could jump as long as I verify the returned information. However, when I connected the data interface later, I reported various errors. After two days of connection, I checked a lot of information, and accepted the ridicule and abuse of the company's elderly, and finally made it.

This is a network session based on session. When the mobile app sends a login request to the server, the header (head) of the network response (networkRespone) returned by the server stores the sessionid you want. At this time, just rewrite parseNetworkResponse:

Step 1: Add this method after errorLitener to get sessionid

{
protected Response<String> parseNetworkResponse(NetworkResponse response){
Response<String> r = (response);
Map<String,String> head = ;
String cookies = ("Set-Cookie");
 = (0,(";"));
return r;
}
};

The above is written on the page when you first log in.

Step 2:

 This is a global variable written by myself,It's very simple to write
public class Contant{
public static volatile String cookie = null;
}

Step 3: Send session when sending data requests

StringRequest request = new StringRequest(, url, listener,
errorListener) {
public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
if ( != null &amp;&amp; () &gt; 0) {
HashMap&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
("cookie", );
("debug", "headers--" + headers);
return headers;
}else {
return ();
}
}
};

The listener and errorlister extensions here can be written outside, and it can be written here, so that's it

The above is the method of maintaining conversations under the Volley framework in Android introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!