Android: If the main thread depends on the execution result of sub-thread A, how can I let the execution of sub-thread A be completed and then the main thread execute further?

  android, question
/*
 String ObjectResult= "original result";
 //Use VOLLY Framework (Independent of Issue)
 JsonObjectRequest jsonObjectRequest = new JsonObjectRequest (url, null , new Listener<JSONObject>(
 ) {
 //Methods in Anonymous Internal Classes
 @Override
 public void onResponse(JSONObject response) {
 ObjectResult = response.toString();
 Log.i("TAG ","internal class: "plus ObjectResult");
 bracket
 });
 queue.add(jsonObjectRequest);
 Log.i("TAG ","external class: "plus ObjectResult");
 */

During the execution of this program, “Log.i(“TAG”, “external class:” plus ObjectResult); “was executed first. The method in the anonymous inner class was executed. Now I want to use subthreads to control it to execute anonymous internal classes first, and then execute operations of external classes. The specific method is What?
Thank you very much!

The method in your internal class cannot be executed until you get the reponse. To achieve your goal, you must implement a callback method yourself. Like this,

@Override
 public void onResponse(JSONObject response) {
 ObjectResult = response.toString();
 callback.dosomething(ObjectResult);  //Self-implemented callback method
 bracket

I strongly suggest you take a look at Observer pattern. In my opinion, Observer pattern’s design idea is very suitable for constructing callback methods. As for the specific implementation, you have to look at ls handler.