我在Awareness API中创建了一个检查fence状态的函数。但我需要返回结果。所以我声明了布尔但是它要求我声明它是最终的。你能帮我解决一下如何返回这个值吗?
public static boolean isFencesActive(final Context context) {
boolean isActive;
Awareness.getFenceClient(context).queryFences(FenceQueryRequest.forFences(Arrays.asList(Constans.DETECTION_FENCE_DRIVING, Constans.DETECTION_FENCE_WALKING)))
.addOnSuccessListener(new OnSuccessListener<FenceQueryResponse>() {
@Override
public void onSuccess(FenceQueryResponse fenceQueryResponse) {
FenceStateMap map = fenceQueryResponse.getFenceStateMap();
isActive = !map.getFenceKeys().isEmpty(); //Needs to be final
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.d(TAG, "Failed: " + e);
isActive = false;
}
});
return isActive;
}
答案 0 :(得分:0)
@Dim,你必须使用类似下面的代码(使用它来达到你想要的目的):
function BaseObject(a) {
this.a = a;
this.MyFunction = function() {
// ...
}
}
function DerivedObject(a, b) {
BaseObject.call(this, a)
this.b = b;
this.MyFunction = function() {
// ...
}
}
var instance = new DerivedObject(someValue, someOtherValue);
instance.MyFunction();
答案 1 :(得分:0)
经过一番考虑后,我明白这是异步任务,这就是我收到错误的原因。我所做的是创建回调,将此信息发送到我的活动。
答案 2 :(得分:-1)
这可能会对您有所帮助,请在全球范围内声明boolean isActive;
变量。