我想了解BroadcastReceivers是如何在安卓系统上工作的。我的问题是,从我在sendBroadcast上调用LocalBroadcastManager的时间到它在我的BroadcastReceiver中收到的时间之间会有延迟吗?调用是同步的吗?
例如,当调用myFunction时,输出是21还是12?
myFunction {
sendBroadcast;
print "1";
}
myReceiver {
print "2";
}如果将运行的函数更改为
myFunction {
sendBroadcast1;
print "1";
sendBroadcast2;
callALotOfOtherFunctions;
}
myReceiver1 {
print "2";
}
myReceiver2 {
print "3";
}从myFunction调用的所有其他函数会在接收者之前调用吗?
发布于 2013-12-20 22:11:17
我相信BroadcastReceiver是异步工作的,所以(我不确定)是的,您的函数可以在完成接收任务之前运行,
你应该试试这个,看看你自己的结果。
myFunction {
sendBroadcast1;
print "1";
sendBroadcast2;
callALotOfOtherFunctions;
}
myReceiver1 {
print("rec1 begins")
sleep(1000)
print("rec1 ends")
}
myReceiver2 {
print("rec2 begins")
sleep(1000)
print("rec2 ends")
}查看在打印之前是否调用了函数
https://stackoverflow.com/questions/20712623
复制相似问题