Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing an IntentService to do Prioritized Networking
    primarykey
    data
    text
    <p>I've been wondering if it is possible to use an <code>IntentService</code> to do some networking while keeping the queue of pending intents prioritized. My goal to be able to download some images in the background, add more if needed (send another <code>Intent</code>) and be able to reset the queue if necessary (preferably using a specific Intent). That is all possible with an <code>IntentServie</code> but when I send that 'stop' <code>Intent</code> it needs to be processed as the next item in the queue, not the last where it is right now.</p> <p>EDIT</p> <p>For those interested I have taken the AOSP code for <code>IntentService</code> and modified it to meet my needs. The reason I cannot just subclass IntentHandler is because of the private <code>ServiceHandler</code> class inside of <code>IntentHandler</code>.</p> <p>Inside of the <code>ServiceHandler</code> I have a new method:</p> <pre><code> public final boolean sendPriorityMessage(Message msg) { int priority = msg.arg2; //Log.i(GenericList.TAG,"recieved message priority: "+priority); if(priority&gt;PRIORITY_NORMAL){ return sendMessageAtFrontOfQueue(msg); }else{ return sendMessage(msg); } } </code></pre> <p>This method is called from <code>onStart</code> instead of just <code>sendMessage</code></p> <pre><code> @Override public void onStart(Intent intent, int startId) { Message msg = mServiceHandler.obtainMessage(); msg.arg1 = startId; msg.obj = intent; try{ msg.arg2 = intent.getExtras().getInt(KEY_PRIORITY); }catch(Exception e){ msg.arg2 = PRIORITY_NORMAL; } mServiceHandler.sendPriorityMessage(msg); } </code></pre> <p>Overall the code is still limited but I am able to fast track some messages to the front of the queue, which is what I was after anyway.</p>
    singulars
    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