Google Map and "realtime" data - Tuong-Nguyen/Android GitHub Wiki

Integrate google map to Android app

References:

Steps

Project configuration

Create Google Maps activity

Sync Data from Server

SyncAdapter

Authenticator

  • Plugs Android accounts and authentication framework for handling user credentials (ex: login)
  • If don't use user account or login, we still need provide an authenticator component but it's stub
  • Bound with a Service that allows the framework call and pass data.

Steps

  • Create stub Authenticator
  • Bind to framework by using Service
  • Add metadata file for Authenticator
  • Declare Authenticator and AuthenticatorService in manifest

https://developer.android.com/training/sync-adapters/creating-authenticator.html

ContentProvider

  • Use to store the local data.
  • If run SyncAdapter without ContentProvider, the sync adapter crashes

Steps

https://developer.android.com/guide/topics/providers/content-provider-creating.html

SyncAdapter

  • Encapsulates the code of tasks that transfer data between the device and server

Steps

  • Create a sync adapter by extends AbsrtactThreadedSyncAdapter
    • Override onPerformSync
      • Connect to server
      • Download and upload data
      • Handling data conflict
      • Clean up
  • Bind SyncAdapter to framework with a Service
  • Add metadata file
  • Declare SyncAdapter and SyncService in manifest
  • Add permissions: android.permission.INTERNET, android.permission.READ_SYNC_SETTINGS, android.permission.WRITE_SYNC_SETTINGS, android.permission.AUTHENTICATE_ACCOUNTS

https://developer.android.com/training/sync-adapters/creating-sync-adapter.html

Get data from ContentProvider

  • Activity implements LoaderManager.LoaderCallbacks<Cursor>
  • Loaders do queries in a background thread
  • Can use ContentObserver that is triggered when data in the content provider changes. When the sync adapter updates the content provider, the ContentObserver responds by resetting the loader and then reloading it.
⚠️ **GitHub.com Fallback** ⚠️