我正在制作一个需要不断查询表中某个属性的应用程序。这是我现在正在做的事情。 我的服务类中的代码:
@Override
public int onStartCommand(Intent intent,int flags,int startId)
{
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
ParseUser currentUser = ParseUser.getCurrentUser();
String username = currentUser.getString("username");
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("isAttacking", username);
while(true)
{
query.findInBackground(new FindCallback<ParseUser>() {
public void done(List<ParseUser> objects, ParseException e) {
if ((e == null)&(objects.size() != 0))
{
// The query was successful.
ParseUser attacker = objects.get(0);
String attackerName = attacker.getUsername();
Log.i("ambustest",attackerName);
makeToast(attackerName);
} else {
Log.i("fd","Something went wrong.");
}
}
});
return START_STICKY;
}
}
查询在无限循环中,但只执行一次。我最好的猜测是它在遇到 return 语句时会中断。有什么方法可以在不将 return 语句放入无法访问的代码的情况下保持循环运行?