var allowUpload = true
var history: String?
val query = AVQuery<AVObject>("MwordsResult")
val currentUser = AVUser.getCurrentUser()
val speed = wordsArray.size.toDouble() / time.toDouble()
query.whereEqualTo("userid", currentUser.objectId)
query.whereEqualTo("unit", getUnitFileUrl(spinner.selectedItem.toString()))
query.orderByAscending("speed")
query.findInBackground().subscribe(object : Observer<MutableList<AVObject?>?> {
override fun onSubscribe(disposable: Disposable) {}
override fun onError(throwable: Throwable) {}
override fun onComplete() {}
override fun onNext(list: MutableList<AVObject?>) {
if (list.size > 0) {
for (i in list.indices) {
if (list[i]?.get("speed").toString().toDouble() <= speed) {
AVObject.createWithoutData("MwordsResult", list[i]?.objectId).delete() //①
} else {
allowUpload = false
history = list[i]?.objectId
}
}
}
if (allowUpload) { //②
val avObject = AVObject("MwordsResult")
大概逻辑是这样的 首先进行一次查询 然后将数据库中的speed列小于变量speed的对象删除 如果发现speed不够就不会进行下面的逻辑并且记录history 运行情况:没有测试speed不够的情况、不存在对象(list.size == 0)可以正常通过②处的if、speed如果更大 对应的对象会删除但是②不会执行 控制台也没输出错误信息 注释掉①处后 ②处的if就可以正常执行了
小白求解答