• Android开发训练之第五章第六节——Transferring Data Using Sync Adapters


    Transferring Data Using Sync Adapters

    DEPENDENCIES AND PREREQUISITES

    • Android 2.1 (API Level 7) or higher

    YOU SHOULD ALSO READ

    TRY IT OUT

    Download the sample

    BasicSyncAdapter.zip

    Synchronizing data between an Android device and web servers can make your application significantly more useful and compelling for your users. For example, transferring data to a web server makes a useful backup, and transferring data from a server makes it available to the user even when the device is offline. In some cases, users may find it easier to enter and edit their data in a web interface and then have that data available on their device, or they may want to collect data over time and then upload it to a central storage area.

    Although you can design your own system for doing data transfers in your app, you should consider using Android's sync adapter framework. This framework helps manage and automate data transfers, and coordinates synchronization operations across different apps. When you use this framework, you can take advantage of several features that aren't available to data transfer schemes you design yourself:

    Plug-in architecture
    Allows you to add data transfer code to the system in the form of callable components.
    Automated execution
    Allows you to automate data transfer based on a variety of criteria, including data changes, elapsed time, or time of day. In addition, the system adds transfers that are unable to run to a queue, and runs them when possible.
    Automated network checking
    The system only runs your data transfer when the device has network connectivity.
    Improved battery performance
    Allows you to centralize all of your app's data transfer tasks in one place, so that they all run at the same time. Your data transfer is also scheduled in conjunction with data transfers from other apps. These factors reduce the number of times the system has to switch on the network, which reduces battery usage.
    Account management and authentication
    If your app requires user credentials or server login, you can optionally integrate account management and authentication into your data transfer.

    This class shows you how to create a sync adapter and the bound Service that wraps it, how to provide the other components that help you plug the sync adapter into the framework, and how to run the sync adapter to run in various ways.

    Note: Sync adapters run asynchronously, so you should use them with the expectation that they transfer data regularly and efficiently, but not instantaneously. If you need to do real-time data transfer, you should do it in an AsyncTask or an IntentService.

    Lessons


    Creating a Stub Authenticator
    Learn how to add an account-handling component that the sync adapter framework expects to be part of your app. This lesson shows you how to create a stub authentication component for simplicity.
    Creating a Stub Content Provider
    Learn how to add a content provider component that the sync adapter framework expects to be part of your app. This lesson assumes that your app doesn't use a content provider, so it shows you how to add a stub component. If you have a content provider already in your app, you can skip this lesson.
    Creating a Sync Adapter
    Learn how to encapsulate your data transfer code in a component that the sync adapter framework can run automatically.
    Running a Sync Adapter
    Learn how to trigger and schedule data transfers using the sync adapter framework.
  • 相关阅读:
    云计算在未来发展中的重要性体现在哪里?
    四大优势凸显,云计算成大势所趋
    边缘计算的今天、明天和未来
    以太坊年底前这5件大事,能否带来大惊喜?
    量子计算是什么?它到底有什么用?
    加快边缘计算发展的十大趋势
    树结构练习——排序二叉树的中序遍历
    树结构练习——排序二叉树的中序遍历
    数据结构实验之二叉树的建立与遍历
    数据结构实验之二叉树的建立与遍历
  • 原文地址:https://www.cnblogs.com/bvin/p/4350723.html
Copyright © 2020-2023  润新知