Home | History | Annotate | Download | only in run-background-service
      1 page.title=Running in a Background Service
      2 page.tags=intentservice
      3 
      4 trainingnavtop=true
      5 startpage=true
      6 
      7 @jd:body
      8 
      9 <div id="tb-wrapper">
     10 <div id="tb">
     11 <h2>Dependencies and prerequisites</h2>
     12 <ul>
     13   <li>Android 1.6 (API Level 4) or higher</li>
     14 </ul>
     15 <h2>You should also read</h2>
     16 <ul>
     17     <li>
     18 <a href="{@docRoot}guide/components/services.html#ExtendingIntentService">Extending the IntentService Class</a>
     19     </li>
     20     <li>
     21         <a href="{@docRoot}guide/components/intents-filters.html">Intents and Intent Filters</a>
     22     </li>
     23 </ul>
     24 <h2>Try it out</h2>
     25 
     26 <div class="download-box">
     27     <a href="{@docRoot}shareables/training/ThreadSample.zip" class="button">Download the sample</a>
     28     <p class="filename">ThreadSample.zip</p>
     29 </div>
     30 
     31 </div>
     32 </div>
     33 <!-- ------------------------------------------------------------------------------------------- -->
     34 <!-- Introduction -->
     35 <!-- ------------------------------------------------------------------------------------------- -->
     36 <p>
     37     Unless you specify otherwise, most of the operations you do in an app run in the foreground on
     38     a special thread called the UI thread. Long-running foreground operations can cause problems
     39     and interfere with the responsiveness of your user interface, which annoys your users and can
     40     even cause system errors. To avoid this, the Android framework offers several classes that
     41     help you off-load operations onto a separate thread that runs in the background. The most
     42     useful of these is {@link android.app.IntentService}.
     43 </p>
     44 <p>
     45     This class describes how to implement an {@link android.app.IntentService}, send it work
     46     requests, and report its results to other components.
     47 </p>
     48 
     49 <p class="note"><strong>Note:</strong> If your app targets Android 5.0 (API level 21),
     50     you should use {@link android.app.job.JobScheduler} to execute background
     51     services. For more information about this class,
     52     see the {@link android.app.job.JobScheduler} reference documentation.</p>
     53 
     54 <h2>Lessons</h2>
     55 <dl>
     56     <dt>
     57         <b><a href="create-service.html">Creating a Background Service</a></b>
     58     </dt>
     59     <dd>
     60         Learn how to create an {@link android.app.IntentService}.
     61     </dd>
     62     <dt>
     63         <b><a href="send-request.html">Sending Work Requests to the Background Service</a></b>
     64     </dt>
     65     <dd>
     66         Learn how to send work requests to an {@link android.app.IntentService}.
     67     </dd>
     68     <dt>
     69         <b><a href="report-status.html">Reporting Work Status</a></b>
     70     </dt>
     71     <dd>
     72         Learn how to use an {@link android.content.Intent} and a
     73         {@link android.support.v4.content.LocalBroadcastManager} to communicate the status of a
     74         work request from an {@link android.app.IntentService} to the
     75         {@link android.app.Activity} that sent the request.
     76     </dd>
     77 </dl>
     78 
     79