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

前端 未结 7 1929
遇见更好的自我
遇见更好的自我 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:48

    I figured out that these workarounds are only worth the effort and the wait only if your bound services are running in a different process than your application's main process.

    For accessing data and methods in the same process (or application), I ended up implementing singleton classes. If the classes need a context for some methods, I leak the application context to the singleton classes. There is, of course, a bad consequence of it as it breaks the "instant run". But that is an overall better compromise, I think.

提交回复
热议问题