Home | History | Annotate | Download | only in sync-adapters
      1 page.title=Transferring Data Using Sync Adapters
      2 
      3 trainingnavtop=true
      4 startpage=true
      5 
      6 
      7 @jd:body
      8 
      9 <div id="tb-wrapper">
     10 <div id="tb">
     11 
     12 <h2>Dependencies and prerequisites</h2>
     13 <ul>
     14     <li>Android 2.1 (API Level 7) or higher</li>
     15 </ul>
     16 
     17 <h2>You should also read</h2>
     18 <ul>
     19     <li>
     20         <a href="{@docRoot}guide/components/bound-services.html">Bound Services</a>
     21     </li>
     22     <li>
     23         <a href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a>
     24     </li>
     25     <li>
     26         <a href="{@docRoot}training/id-auth/custom_auth.html">Creating a Custom Account Type</a>
     27     </li>
     28 </ul>
     29 
     30 <h2>Try it out</h2>
     31 
     32 <div class="download-box">
     33  <a href="http://developer.android.com/shareables/training/BasicSyncAdapter.zip" class="button">Download the sample</a>
     34  <p class="filename">BasicSyncAdapter.zip</p>
     35 </div>
     36 
     37 </div>
     38 </div>
     39 <p>
     40     Synchronizing data between an Android device and web servers can make your application
     41     significantly more useful and compelling for your users. For example, transferring data to a web
     42     server makes a useful backup, and transferring data from a server makes it available to the user
     43     even when the device is offline. In some cases, users may find it easier to enter and edit their
     44     data in a web interface and then have that data available on their device, or they may want to
     45     collect data over time and then upload it to a central storage area.
     46 </p>
     47 <p>
     48     Although you can design your own system for doing data transfers in your app, you should
     49     consider using Android's sync adapter framework. This framework helps manage and automate data
     50     transfers, and coordinates synchronization operations across different apps. When you use
     51     this framework, you can take advantage of several features that aren't available to data
     52     transfer schemes you design yourself:
     53 </p>
     54 <dl>
     55     <dt>
     56         Plug-in architecture
     57     </dt>
     58     <dd>
     59         Allows you to add data transfer code to the system in the form of callable components.
     60     </dd>
     61     <dt>
     62         Automated execution
     63     </dt>
     64     <dd>
     65         Allows you to automate data transfer based on a variety of criteria, including data changes,
     66         elapsed time, or time of day. In addition, the system adds transfers that are unable to
     67         run to a queue, and runs them when possible.
     68     </dd>
     69     <dt>
     70         Automated network checking
     71     </dt>
     72     <dd>
     73         The system only runs your data transfer when the device has network connectivity.
     74     </dd>
     75     <dt>
     76         Improved battery performance
     77     </dt>
     78     <dd>
     79         Allows you to centralize all of your app's data transfer tasks in one place, so that they
     80         all run at the same time. Your data transfer is also scheduled in conjunction with data
     81         transfers from other apps. These factors reduce the number of times the system has to
     82         switch on the network, which reduces battery usage.
     83     </dd>
     84     <dt>
     85         Account management and authentication
     86     </dt>
     87     <dd>
     88         If your app requires user credentials or server login, you can optionally
     89         integrate account management and authentication into your data transfer.
     90     </dd>
     91 </dl>
     92 <p>
     93     This class shows you how to create a sync adapter and the bound {@link android.app.Service} that
     94     wraps it, how to provide the other components that help you plug the sync adapter into the
     95     framework, and how to run the sync adapter to run in various ways.
     96 </p>
     97 <p class="note">
     98     <strong>Note:</strong> Sync adapters run asynchronously, so you should use them with the
     99     expectation that they transfer data regularly and efficiently, but not instantaneously. If
    100     you need to do real-time data transfer, you should do it in an {@link android.os.AsyncTask} or
    101     an {@link android.app.IntentService}.
    102 </p>
    103 <h2>Lessons</h2>
    104 <dl>
    105     <dt>
    106         <b><a href="creating-authenticator.html">Creating a Stub Authenticator</a></b>
    107     </dt>
    108     <dd>
    109         Learn how to add an account-handling component that the sync adapter framework expects to be
    110         part of your app. This lesson shows you how to create a stub authentication component for
    111         simplicity.
    112     </dd>
    113     <dt>
    114         <b><a href="creating-stub-provider.html">Creating a Stub Content Provider</a></b>
    115     </dt>
    116     <dd>
    117         Learn how to add a content provider component that the sync adapter framework expects to be
    118         part of your app. This lesson assumes that your app doesn't use a content provider, so it
    119         shows you how to add a stub component. If you have a content provider already in your app,
    120         you can skip this lesson.
    121     </dd>
    122     <dt>
    123         <b><a href="creating-sync-adapter.html">Creating a Sync Adapter</a></b>
    124     </dt>
    125     <dd>
    126         Learn how to encapsulate your data transfer code in a component that the sync
    127         adapter framework can run automatically.
    128     </dd>
    129     <dt>
    130         <b><a href="running-sync-adapter.html">Running a Sync Adapter</a></b>
    131     </dt>
    132     <dd>
    133         Learn how to trigger and schedule data transfers using the sync adapter framework.
    134     </dd>
    135 </dl>
    136