Note that there are some explanatory texts on larger screens.

plurals
  1. POincorrect work methods bindServer() when trying to connect to the service, after the application is restarted
    primarykey
    data
    text
    <p>Today, working with the Service for Android, has faced some "illogical" or "not correctly", in my opinion, the work method <code>bindService</code>. The essence of the confusion that I created in the application service that is within you, with the <code>ExecutorService</code> makes a request. When I went to the application, the service remained alive - the queries are executed in separate threads with a certain cyclical (logs confirm this). In the method onStart() I have written code that, by all manuals and tutorials should give me access to the service, that I have run before, with this application. But all our advise it seemed evident. I expected that calling <code>bindService()</code> -> I get a connection to a running service. But no, instead, at the first attempt the connection is not happening - I do not understand why. I added code that would run the service itself, if it has not been done before. So this part of the code is activated and again I try to connect to just running the service. And yes, the connection is successful, but - connection nourish my service I was expecting to get from the first connection attempt. And judging from the logs of my attempt to re-create the service does not lead to its creation. All this follows from the log. And in this regard, I wonder - why the first attempt to connect it does not happen? Or am I doing wrong?</p> <p><strong>fragment code in Activity</strong></p> <pre><code>... private ServiceConnection serviceConnection = new ServiceConnection(){ public void onServiceConnected(ComponentName name, IBinder service) { flagServiceConnection = true; Log.d("StartActivity/serviceConnection", "serviceConnection/onServiceConnected() -&gt; connected"); exService = ((ExService.ExBinder) service).getService(); exService.setFlagBroadcast(true); exService.getAll(); } public void onServiceDisconnected(ComponentName name) { flagServiceConnection = false; Log.d("StartActivity/serviceConnection", "serviceConnection/onServiceDisconnected() -&gt; disconnected"); } }; ... public void onStart(){ super.onStart(); bindService(new Intent(this.getApplicationContext(), ExService.class), serviceConnection, 0); if(!flagServiceConnection){ Log.d("StartActivity", "onStart() -&gt; start service"); this.startService(new Intent(this.getApplicationContext(), ExService.class)); bindService(new Intent(this.getApplicationContext(), ExService.class), serviceConnection, 0); } } </code></pre> <p><strong>Log</strong></p> <pre><code>D/StartActivity(5922): onCreate() D/StartActivity(5922): onStart() -&gt; start service D/StartActivity/serviceConnection(5922): erviceConnection/onServiceConnected() -&gt; connected D/-(5922): pront.android.exservice.ExService$Monitor@4056b4c8 D/-(5922): pront.android.exservice.ExService$Monitor@405480e0 D/-(5922): pront.android.exservice.ExService$Monitor@4054ee18 D/ExService(5922): onRebind() D/ExService(5922): onStartCommand() -&gt; service start </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.
    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