9
9

More than 5 years have passed since last update.

Intro

SyncAdapterについて.

  • SyncAdapterはスケジュールされた同期タスクに向いている
  • 同期のポリシーを指定するだけで後はAndroidがよしなにスケジュールする
  • 採用できる同期のポリシーは次の通り
    • サーバデータ変更時のメッセージ通知受信時(use GCM)
    • デバイスデータ変更時
    • TCP/IPコネクション接続時
    • 一定時間or指定時間 (厳密ではない(効率優先))
    • オンデマンド (not require)
  • バッテリーやネットワークリソースに易しい設計である
  • Authenticator機能を使用してログインが必要なサーバとも同期可能
  • Authenticator機能が不要であればスタブでよい(アカウントは必須ではない)
  • ContentProviderと連携したデータ管理, 操作をサポートする
  • ContentProviderの使用は必須ではないが強く推奨されている

Transferring Data Using Sync Adapters

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.

AndroidデバイスとWebサーバー間のデータ同期を行うアプリケーションは魅力的に映る. 例えばデータをサーバに移してバックアップをとったり, サーバからデータを取得してオフライン操作を可能にする. Webインタフェースを使ってデータを簡単に見つけたり編集したりでき, それらのデータをAndroidデバイス上でも使うことができる. 時間をかけて集めたデータをサーバにアップロードして管理することも可能だ.

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:

アプリでデータ転送を行う場合, Android標準のsync adapter frameworkの使用を検討すべきである. このframeworkはデータの管理と自動転送の手段を提供する. そして, 端末にあるアプリ全体のデータ同期タイミングを調整してくれる. このframeworkを使用するといくつかのアドバンテージを得られる.

Plug-in architecture
: Allows you to add data transfer code to the system in the form of callable components.

Plug-in architecture
: データ転送のロジックを呼出し可能なコンポーネントにしてシステムへ追加できる

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 execution
: データが更新された時や一定間隔置き, 指定時間といった様々な契機でデータ転送を自動実行できる. また, 実行できなかったものはキューイングされ良しなに再開される.

Automated network checking
: The system only runs your data transfer when the device has network connectivity.

Automated network checking
: システムはネットワーク接続が有効な時にデータ転送を実行する.

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.

improved battery performance
: システムはデータ転送タスクを一元管理して, 同時実行されてもシステムはうまくタスクスケジューリングしてくれる. これによりネットワーク接続の回数を減らしてバッテリー消費を抑える.

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.

Account management and authentication
: もし, ユーザのサーバログインが必要であればオプションでAccount ManagementとAuthenticatorとも統合されることができる.

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.

ここでは, どうやってsync adapterとバインドされたServiceを作成するのか, frameworkにsync adapterを差し込むために必要なコンポーネントをどうやって提供するのか, そして, sync adapterを実行する方法をいくつか紹介する.

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.

Note: Sync adapterは非同期実行され, 定期的かつ効率的なデータ転送を用途としており, 即時同期を期待すべきではない. もし即時性を求めるならばAsyncTaskIntentServiceの使用を検討すべき.

since: 2014.09.19
source: http://developer.android.com/training/sync-adapters/index.html

続き➡ Yukiの枝折 Android:SyncAdapter http://yuki312.blogspot.jp/2014/09/androidsyncadapter.html

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9