为什么在回复之间同时发送邮件这么长时间?
更新:我还检查了服务收到消息的时间。事实证明,服务在指数时间内收到消息,发送回复的时间大致不变。那么为什么系统会以这种方式将消息发送给服务呢?
update2:这本身不是代码。更多缺少非相关行的抽象或伪代码
客户活动:
Messenger mMessenger // this Activity's messenger
Messenger mService // Service Messenger initialised through binding
onClick(View view) {
for(i=0; i<100; i++) {
callMessage();
}
}
callMessage() {
Message msg = Message.obtain(null, 1234, 0, 0);
Bundle data = new Bundle();
data.putLong("sent", new Date().getTime());
msg.setData(data);
msg.replyTo = mMessenger; //this.Handler
try {
mService.send(msg);
} catch (RemoteException e) {
e.printStackTrace();
}
}
// in Handler
public void handleMessage(Message msg) {
long now = new Date().getTime();
long timeelapsed = now - msg.getData().getLong("sent");
updateTextView(timeelapsed);
}
远程服务:
public void handleMessage(Message msg) {
// create a new message reply
reply.getData().putLong("sent",msg.getData().getLong("sent"));
msg.replyTo.send(reply);
}
结果:
(毫秒) 54 96 135 ... ... 606 ... ... 1568 ... ... 等等