How to operate the network in a method with a return value and then return the value after the network operation?

  android, question

How to operate the network in a method with a return value and then return the value after the network operation?

such as

private String A(){
 
 String requeststringrequest = newstringrequest (request.method.post, myapplication.host plus "/mobileLogin.do",
 new Response.Listener<String>() {
 @Override
 public void onResponse(String s) {
 Sout ("acquired" plus s)
 bracket
 }, new Response.ErrorListener() {
 @Override
 public void onErrorResponse(VolleyError volleyError) {
 
 bracket
 }){
 @Override
 protected Map<String, String> getParams() throws AuthFailureError {
 Map<String,String> map=new HashMap<>();
 map.put("msgno","001010");
 map.put("uid",s);
 return super.getParams();
 bracket
 };
 requestQueue.add(stringRequest);
 bracket
I want to return the obtained result, but volley's operation is asynchronous and there is no return at all. What about this

Interface callback can be used

  1. First declare an interface

public interface RequestCallback{
 void onSuccess(String data);
 void onFail(String error);
 bracket
  1. And then used within the method

private String A(RequestCallback callback){
 
 String requeststringrequest = newstringrequest (request.method.post, myapplication.host plus "/mobileLogin.do",
 new Response.Listener<String>() {
 @Override
 public void onResponse(String s) {
 Sout ("acquired" plus s)
 if(callback!  =null){
 callback.onSuccess(s);
 bracket
 
 bracket
 }, new Response.ErrorListener() {
 @Override
 public void onErrorResponse(VolleyError volleyError) {
 if(callback!  =null){
 callback.onFail(volleyError.getMessage);
 bracket
 
 bracket
 }){
 @Override
 protected Map<String, String> getParams() throws AuthFailureError {
 Map<String,String> map=new HashMap<>();
 map.put("msgno","001010");
 map.put("uid",s);
 return super.getParams();
 bracket
 };
 requestQueue.add(stringRequest);
 bracket