What happens if a Android Service is started multiple times?

后端 未结 4 885
一生所求
一生所求 2020-11-29 23:22

If I have the following code:

Intent intent = new Intent(this,DownloadService.class);     
for(int i=0;i

        
4条回答
  •  庸人自扰
    2020-11-29 23:58

    Absolutely Correct. Only one instance of Service is created for an application process. And when you call StartService(); again, then only onStartCommand() gets called and new Intent is passed to onStartCommand() method.

    Note: onCreate() is not called again.

    About calling bindService() multiple times:

    When you call bindService() multiple times, then again only one instance is used for Service and Android Runtime returns same IBinder object to client.

    Means, onBind() is not called multiple times. And just cached IBinder object is returned.

提交回复
热议问题