Note that there are some explanatory texts on larger screens.

plurals
  1. POsubsequent onBind() calls are not triggered
    primarykey
    data
    text
    <p>using gingerbread 2.3.4 api lvl 10.</p> <p>I am starting a service after boot completed. To do so I added a broadcast receiver which starts the service.I am using the same service in the launcher. I am trying to bind to service by adding extra params to Intent. Getting back results from service by broadcast reply.</p> <p>The problem is when it first binds, the onBind() on the service is triggered. Further bindings does not call the onBind() on the service. I believe the problem is service starting directly after_boot. When I dont start the service in bootup and let the activity start it with Context.BIND_AUTO_CREATE it does behave as expected.</p> <p>The only solution I came up with is changing the onUnbind() of the service and issuing onBind() in onRebind() call of the service. I dont like this solution since it might break in later android versions leading the onBind() method being called twice.</p> <p>So why doesn't subsequent binds are not triggered on the services which start up after boot completed. Any other elegant solutions are welcome. </p> <p>PS: I already implemented it in aidl, but I dont like it, since the service will be doing some async stuff to return data back and I have to add aidl files in both apps, will add handlers which leads to bloated code.</p> <p>Thanks in advance. Snippet of my code:</p> <p>Manifest of the service: </p> <pre><code> &lt;intent-filter&gt; &lt;action android:name="com.organization.android.ACTION_BOOT_COMPLETED" /&gt; &lt;/intent-filter&gt; &lt;intent-filter&gt; &lt;action android:name="com.organization.android.WORK_INTENT" /&gt; &lt;/intent-filter&gt; &lt;/service&gt; &lt;receiver android:name=".CoreServiceReceiver" &gt; &lt;intent-filter&gt; &lt;action android:name="android.intent.action.BOOT_COMPLETED" &gt; &lt;/action&gt; &lt;category android:name="android.intent.category.HOME" &gt; &lt;/category&gt; &lt;/intent-filter&gt; &lt;/receiver&gt; </code></pre> <p>When I bind to the service:</p> <p>Intent intent = new Intent(WORK_INTENT); intent.putExtra("param", param);</p> <pre><code>context.registerReceiver (broadcastReceiver, new IntentFilter("com.organization.android.WORK_RESULT")); context.bindService(intent,mConnection, Context.BIND_AUTO_CREATE); </code></pre> <p>}</p> <p>When I get the result:</p> <pre><code>context.unbindService(mConnection); context.unregisterReceiver (broadcastReceiver); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload