【发布时间】:2016-12-20 20:59:45
【问题描述】:
我正在 Android Studio 中实现 Helper 类来服务 Activity
public void getLastId()
{
//init OkHttpClient
OkHttpClient client = new OkHttpClient();
//backend url
Request request = new Request.Builder()
.url("http://192.168.1.102:8080/aquabackend/public/customers/lastid")
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
}
@Override
public void onResponse(Call call, Response response) throws IOException {
String jsonData = response.body().string();
try {
JSONObject jobject = new JSONObject(jsonData);
String id = jobject.getString("id");
//increment current id +1
String last_id = String.valueOf(Integer.parseInt(id)+1);
Log.i("new id", last_id);
} catch (Exception e) {
e.printStackTrace();
}
//Log.i("ok", response.body().string());
}
});
我在活动类中的函数调用
Helper helper = new Helper();
helper.getLastId();
//I want to get method to return lastId and then manipulate with the data
如何让方法返回id的值?
【问题讨论】:
标签: android android-asynctask okhttp3