Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should look at creating your own <a href="http://developer.android.com/reference/android/os/ResultReceiver.html" rel="noreferrer"><code>ResultReceiver</code></a> subclass in your activity. <code>ResultReceiver</code> implements <code>Parcelable</code> so can be passed from your <code>Activity</code> to your <code>Service</code> as an extra on the <code>Intent</code>.</p> <p>You'll need to do something like this:</p> <ol> <li><p>Implement a subclass of <code>ResultReceiver</code> within your activity class. The key method to implement is <code>onReceiveResult()</code>. This method provides you a with <code>Bundle</code> of result data which can be used to pass whatever information you are retrieving in your <code>Service</code>. Simply unpack the data you need and use it to update your activity. </p></li> <li><p>In your activity, create a new instance of your custom <code>ResultReceiver</code> and add it to the <code>Intent</code> you use to start your service.</p></li> <li><p>In your <code>Service</code>'s <code>onStartCommand()</code> method, retrieve the <code>ResultReceiver</code> passed in on the <code>Intent</code> and store it in a local member variable.</p></li> <li><p>Once your <code>Service</code> completes its work, have it call <code>send()</code> on the ResultReceiver passing whatever data you want to send back to the activity in a <code>Bundle</code>. </p></li> </ol> <p>This is a pretty effective pattern and means you're not storing data in nasty static variables. </p>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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