Android Service can be bind without start?

前端 未结 2 982
孤街浪徒
孤街浪徒 2020-12-10 18:24

In many articles, tutorials, docs, have read so far, that we call startService() or bindService(), both starts the service. We can call both also, but that\'s a different st

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 18:51

    Yes.

    bindService(new Intent(this, MyService.class), mConnection, 0);
    

    AFAIK, this will always return true (assuming there is no problem with MyService)

    There are two scenarios:

    1. The service has previously been started - mConnection's onServiceConnected() is called
    2. The service has NOT previously been started - mConnection's onServiceConnected() is NOT called and the service is NOT started. However, as soon as the service is started (by some other means), the onServiceConnected() is then called

    In practice, when I call this method, I assume the service is not started until the onServiceConnected() method is called.

提交回复
热议问题