Android how do I wait until a service is actually connected?

前端 未结 7 1909
遇见更好的自我
遇见更好的自我 2020-12-02 12:50

I have an Activity calling a Service defined in IDownloaderService.aidl:

public class Downloader extends Activity {
 IDownloaderService downloader = null;
//         


        
7条回答
  •  攒了一身酷
    2020-12-02 13:35

    How can I wait for ServiceConnection.onServiceConnected being called reliably?

    You don't. You exit out of onCreate() (or wherever you are binding) and you put you "needs the connection established" code in onServiceConnected().

    Are all the event handlers: Activity.onCreate, any View.onClickListener.onClick, ServiceConnection.onServiceConnected, etc. actually called in the same thread

    Yes.

    When exactly is ServiceConnection.onServiceConnected actually going to be called? Upon completion of Activity.onCreate or sometime when A.oC is still running?

    Your bind request probably is not even going to start until after you leave onCreate(). Hence, onServiceConnected() will called sometime after you leave onCreate().

提交回复
热议问题