Java 从Android异步嵌套类返回值
我试图从函数中的嵌套类中返回一个变量,如下所示:Java 从Android异步嵌套类返回值,java,android,azure,asynchronous,Java,Android,Azure,Asynchronous,我试图从函数中的嵌套类中返回一个变量,如下所示: public int getPlan(int planID) { int planId; TableOperationCallback<Plans> callback = new TableOperationCallback<Plans>() { public void onCompleted(Plans plan, Exception exception,ServiceFilterResponse
public int getPlan(int planID) {
int planId;
TableOperationCallback<Plans> callback = new TableOperationCallback<Plans>() {
public void onCompleted(Plans plan, Exception exception,ServiceFilterResponse response) {
if(exception == null){
int planId = (int) db.addPlan(plan); //Want to return this value
} else {
Log.e(exception.getMessage(), "ERROR");
}
}
};
mPlanTable.lookUp(planID, callback);
return planId;
}
public int-getPlan(int-planID){
内平面;
TableOperationCallback callback=新建TableOperationCallback(){
未完成公共无效(计划、异常、ServiceFilterResponse响应){
if(异常==null){
int planId=(int)db.addPlan(plan);//要返回此值吗
}否则{
Log.e(exception.getMessage(),“ERROR”);
}
}
};
查找(planID,回调);
返回平面;
}
此方法与Azure Android SDK链接,可移植。异步调用lookUp()。因此,planId
有时与上述代码一起返回null
返回实际值的最佳方法是什么?如果查找是异步的,则永远不会返回其结果。您需要重构代码,以便使用返回值的任何操作都在回调中完成,而不是在回调中完成。如果查找是异步的,则永远不会返回其结果。您需要重构代码,以便使用返回值的任何操作都在回调中完成,而不是在回调中完成