bindService是否直接调用ServiceConnection.onServiceConnected?

时间:2018-09-20 15:49:32

标签: java android android-service

考虑以下代码:

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已经被调用了?

0 个答案:

没有答案