Return value from inner class in a method
<p>I am building a Login system for an Android app. I am using <a href="http://square.github.io/okhttp/" rel="nofollow">OkHttp</a> to connect to my server and get a JSON response. </p>

<p>I have defined a class with the login return data (right now just a true/false response based on whether the user exists in the database), and then written the code to connect to the server, as shown below:</p>

<pre><code>class UserLogin {
    boolean status;

    public void setStatus(boolean status) {
        this.status = status;
    }

    public boolean getStatus() {
        return status;
    }
}

public class ClientServerInterface {

    OkHttpClient client = new OkHttpClient();

    boolean login(Request request) {
        final Gson gson = new Gson();
        client.newCall(request).enqueue(new Callback() {
            UserLogin login;
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                login = gson.fromJson(response.body().charStream(), UserLogin.class);
                login.setStatus(login.status);
            }
        });
        // need to return the boolean response (status) here
    }
}
</code></pre>

<p>The code which passes the <code>Request</code> variable to the <code>login</code> method works perfectly. I want <code>login</code> to return a boolean response so that I can pass that to other methods in other classes.</p>

<p>However, because the <code>UserLogin</code> object is defined in the <code>callback</code> I can't access it in the parent method. I have made a <code>getStatus</code> method but not sure how to use it properly to get the status in the main <code>login</code> method.</p>