现在我在IntentService
中有意向,它跟踪Service
对intents的排队情况。我发现方法永远不会恢复正常,即使对于相同的意图。还有什么我需要做比较两个意图?如何比较两个意图是否相等
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if(queue.contains(intent)){
//Never reaches here
intent.setAction(NO_ACTION);
}
queue.push(intent);
return super.onStartCommand(intent, flags, startId);
}
用于发送意图示例代码:
Intent i = new Intent(context, NodeIndexService.class);
i.setAction(NodeIndexService.REFRESH);
i.putExtra(NodeIndexService.TYPE, indexType);
i.putExtra(NodeIndexService.RESULT_RECEIVER, receiver);
context.startService(i);
两个目的被发送一个接一个地与此代码应该是相同的,没有?上下文没有改变,额外功能也是一样的。
你所说的“相同”的意图是什么意思?你需要定义它们意味着它们是平等的,否则它只会做对象身份。 –
“相同”意味着相同的动作,类型和附加。我假定如果两个intent被释放,并且这些参数在各自的Intent上相等,equals()将返回true。 – SeanPONeil