考虑以下代码:
ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder serviceBinder) {
// code
}
// ...
};
void register() {
Intent intent = new Intent(this, SomeService.class);
bindService(intent, connection, Context.BIND_AUTO_CREATE);
// code that relies on something executed in connection.onServiceConnected
}
bindService
是否直接呼叫onServiceConnected
?换句话说,是否可以保证在bindService(...)
之后的下一个语句中,connection.onServiceConnected
已经被调用了?