If I understand your question correctly, you ask how you can write a variable from an anonymous class.
Anonymous classes can only access finite variables and cannot directly "write" them.
A simple solution that is “good enough” is to create a ValueBox class with one value field and a receiver and an installer. Then you can create a new instance of the function as a final variable and access your anonymous class. An anonymous class will use its getter and setter for writing / reading.
The fact that the variable is final means that you cannot direct the link elsewhere, but you can still change the contents of the mentioned object from any function.
The big problem you are facing is waiting for a callback call. This kind of wait-sleep may be good enough, but you might think about timeouts, threads, etc., depending on what you are trying to achieve.
Moreover, all of this assumes that you will never call it twice in a mix. Otherwise, you need to provide us with additional information about your synchronization model.
Here is a sample code:
public int getUserid(String username) { final ValueBox<Integer> userid = new ValueBox<Integer>(); connection.call("getUserid", new Responder() { public void onResult(final int result) { System.out.println("userid: " + result); userId.setValue(result);
Uri
source share