tag:blogger.com,1999:blog-8214401912480503366.post4985035690744566847..comments2023-08-10T13:35:15.093+02:00Comments on My life with Android :-): Oneway interfacesGabor Pallerhttp://www.blogger.com/profile/14307475522972458932noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-8214401912480503366.post-26355210048066600722017-10-04T11:49:50.020+02:002017-10-04T11:49:50.020+02:00Elangovan, as I wrote the onBind *is* called once ...Elangovan, as I wrote the onBind *is* called once for the same Intent. <a href="https://developer.android.com/reference/android/content/Intent.html#filterEquals%28android.content.Intent%29" rel="nofollow">Intent.filterEquals</a> defines, when two intents are the same. It says:<br /><i>Determine if two intents are the same for the purposes of intent resolution (filtering). That is, if their action, data, type, class, and categories are the same. This does not compare any extra data included in the intents.</i><br /><br />So filterEquals does not consider the extras but if other fields are different, they are different Intents. In our case, the category was different. As filterEquals does not match, the machinery behind the IBinder caching does not consider the two bindService requests connecting to the same service, even though the invocation eventually ends up in the same Java implementation (CounterService.java). Gabor Pallerhttps://www.blogger.com/profile/02390936870056951146noreply@blogger.comtag:blogger.com,1999:blog-8214401912480503366.post-34669790475323481552017-10-02T19:04:18.565+02:002017-10-02T19:04:18.565+02:00Hi Gabor,
That's interesting. In my experien...Hi Gabor, <br /><br />That's interesting. In my experience I saw the onBind method called only once for a service lifetime even though multiple clients binds to the same service. it is different story if the service is destroyed and recreated again.<br /><br />Could you please provide your feedback on the following explanation from google's android developer's site. <br /><br />https://developer.android.com/guide/components/bound-services.html#Basics<br /><br />"You can connect multiple clients to a service simultaneously. However, the system caches the IBinder service communication channel. In other words, <b> the system calls the service's onBind() method to generate the IBinder only when the first client binds. The system then delivers that same IBinder to all additional clients that bind to that same service, without calling onBind() again.</b>"<br /><br />May be we are not talking about the same thing?Elangovan Manickamhttps://www.blogger.com/profile/06528923301361838364noreply@blogger.comtag:blogger.com,1999:blog-8214401912480503366.post-66872971887616425042017-09-27T00:43:55.072+02:002017-09-27T00:43:55.072+02:00Elangovan, you are wrong when you say that in this...Elangovan, you are wrong when you say that in this case the service will be bound once. Even though it is the same service implementation (CounterService.java), it is bound by different Intents hence considered different services by the Android service framework. If you don't believe, try it yourself. I now updated the post with sources adapted to newer Android tool chains (in particular, the aexp.oneway package name crashed the 25.0 aidl tool because it thought that "oneway" in the package name is a keyword hence every package name has been renamed "one_way") and ran the example on my Nexus 5 (Android 6.0.1).<br /><br />The service is bound twice:<br />09-27 00:24:44.701 25653 25653 D ONEWAYACTIVITY: bindService(): IncreaseCounter<br />09-27 00:24:44.702 25653 25653 D ONEWAYACTIVITY: bindService(): Counter<br /><br />and onBind is called twice:<br />09-27 00:24:44.710 25653 25653 D COUNTERSERVICE: onCreate<br />09-27 00:24:44.710 25653 25653 D COUNTERSERVICE: onBind: Intent { cat=[android.intent.category.aexp.one_way.if.increasecounter] cmp=aexp.one_way/.CounterService }<br />09-27 00:24:44.710 25653 25653 D COUNTERSERVICE: category: android.intent.category.aexp.one_way.if.increasecounter<br />09-27 00:24:44.711 25653 25653 D COUNTERSERVICE: onBind: Intent { cat=[android.intent.category.aexp.one_way.if.counter] cmp=aexp.one_way/.CounterService }<br />09-27 00:24:44.711 25653 25653 D COUNTERSERVICE: category: android.intent.category.aexp.one_way.if.counter<br />09-27 00:24:44.726 25653 25653 D ONEWAYACTIVITY: IncreaseCounterServiceConnection::onServiceConnected<br />09-27 00:24:44.727 25653 25653 D ONEWAYACTIVITY: CounterServiceConnection::onServiceConnected<br /><br />Please, observe that even though the service class is the same (aexp.one_way.CounterService), the Android service framework handles these two services separately. As they are indeed separate services.Gabor Pallerhttps://www.blogger.com/profile/02390936870056951146noreply@blogger.comtag:blogger.com,1999:blog-8214401912480503366.post-14302502753194702572017-09-20T14:57:34.167+02:002017-09-20T14:57:34.167+02:00I know this thread is 7 years old now. But I just ...I know this thread is 7 years old now. But I just want to point few things about this blog.<br /><br />First, the onBind() method on the service will receive the call only once in its lifetime. Even though multiple clients trying to bind to the same service, the android system just returns the cached IBinder object without calling the onBind method. So I couldn't understand how your 'If' condition in the onBind method will work. if you want them to work then you need to stop the service before binding again.<br /><br />Second, the oneway keyword don't have any impact if the service and client are in same application or in same process. Your example looks like having all in one app. So the asynchronous behavior that you expect wont happen. <br /><br />Elangovan Manickamhttps://www.blogger.com/profile/06528923301361838364noreply@blogger.comtag:blogger.com,1999:blog-8214401912480503366.post-86425497089533739882010-04-17T22:49:49.137+02:002010-04-17T22:49:49.137+02:00cool example thanks for sharing!cool example thanks for sharing!michalhttps://www.blogger.com/profile/10506941322182177655noreply@blogger.comtag:blogger.com,1999:blog-8214401912480503366.post-80880907090130438812010-04-01T14:22:25.829+02:002010-04-01T14:22:25.829+02:00?
I am not aware of such a method in Android ...? <br />I am not aware of such a method in Android ...Gabor Pallerhttps://www.blogger.com/profile/14307475522972458932noreply@blogger.comtag:blogger.com,1999:blog-8214401912480503366.post-15448810190097686932010-03-30T23:13:46.827+02:002010-03-30T23:13:46.827+02:00releaseService() isn't invoked in onDestory in...releaseService() isn't invoked in onDestory in the enclosed example... :-)Anonymousnoreply@blogger.com