Note that there are some explanatory texts on larger screens.

plurals
  1. POSending message from service to UI-Thread - Messages delayed in service's handler
    primarykey
    data
    text
    <p>I have a service which is pulling data from the server. And I have activity as gui which needs to get updated.</p> <p>So on different occassions, e.g. the information was pulled from the server successfully, the server must signal the activity that there is new information.</p> <p>For this I implemented this function:</p> <pre><code> /** * ServerService.class * * Sends a message to the observer that there is a new status message to be * pulled from the service# * * @param pMessage * the message to be set to the public status */ private void signalNewStatus(String pMessage) { //check if there is a message at all to be signaled as new if (pMessage != null) { Log.v(tag, "signalNewStatus:" + pMessage); // set the message vStatus = pMessage; // start the new callback via the handler myMessageHandler.sendEmptyMessage(I_STATUS_UPDATE_SIGNAL); } } </code></pre> <p>To handle the messages, I have the message handler:</p> <pre><code> private final Handler myMessageHandler = new Handler() { @Override public void handleMessage(Message msg) { Log.i(tag, "handleMessage: "+msg.what); switch (msg.what) { case I_STATUS_UPDATE_SIGNAL: { // Broadcast to all clients the new value. final int N = myCallbackList.beginBroadcast(); for (int i = 0; i &lt; N; i++) { try { myCallbackList.getBroadcastItem(i).sendUpdateStatusSignal(true); } catch (RemoteException e) { } } myCallbackList.finishBroadcast(); } break; </code></pre> <p>The first function is called quite often, and I can see in the logging that this works right on time. </p> <p>But the logging for the message handling does not get called right away. It is delayed and gets called most often at the end. Somehow as bulk.</p> <p>I cannot figure out why this is the case. The rest works well, the message gets to the UI thread without a problem once the message was handled. </p> <p>Any suggestions?</p> <p>Thanks a lot!</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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