Top Banner
R.A.P. Rely on Android Platform
39

R.A.P. (Rely on Android Platform)

Jul 02, 2015

Download

Technology

Aditium

Slides for droidcon spain 2014.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: R.A.P. (Rely on Android Platform)

R.A.P.Rely on Android Platform

Page 2: R.A.P. (Rely on Android Platform)

DISCLAIMER

Page 3: R.A.P. (Rely on Android Platform)

@ibai_iturricha

● NFC● Android● Django

CTO en Aditium

Page 4: R.A.P. (Rely on Android Platform)

Why should I RAP?

Page 5: R.A.P. (Rely on Android Platform)

My app …manages user accountsloads/pulls data from/to serverworks without connectionand ...

Page 6: R.A.P. (Rely on Android Platform)

I want to be a winner!

Page 7: R.A.P. (Rely on Android Platform)

Decouple authentication from business logic

Page 8: R.A.P. (Rely on Android Platform)

Isolate synchronization strategy

Page 9: R.A.P. (Rely on Android Platform)

Offline first

Page 10: R.A.P. (Rely on Android Platform)

Modular UI Components

Page 11: R.A.P. (Rely on Android Platform)

http://rapgenius.com/discussions/12681-New-version-of-the-last-supper

Time to RAP homies!

Page 12: R.A.P. (Rely on Android Platform)

Android Platform crew

Account Manager manages user credentials

Sync Manager keeps data up to date

Content Provider stores structured data

Loaders make data available

Page 13: R.A.P. (Rely on Android Platform)

Account Manager

“Account Manager provides access to a centralized registry of the user's online accounts”

Android developers

Page 14: R.A.P. (Rely on Android Platform)

Android Platform

Account Manager

Your App

Service

AbstractAccountAuthenticator

AccountAuthenticatorActivity

Page 15: R.A.P. (Rely on Android Platform)

Android Platform

Account Manager

Your App

Service

AbstractAccountAuthenticator

AccountAuthenticatorActivity

Your app

Add account Get auhtToken

Delete account

Page 16: R.A.P. (Rely on Android Platform)

AbstractAccountAuthenticator

Page 17: R.A.P. (Rely on Android Platform)

SyncManager/Adapter

“The ability of the system to help you synchronize remote and local content”

Virgil Dobjanschi (Google IO 201)

Page 18: R.A.P. (Rely on Android Platform)

App 1 App 2 App 3 App 4

Perform a sync → Network request, parceling, DB operations, etc...

Page 19: R.A.P. (Rely on Android Platform)

Sepherd wanted!

Page 20: R.A.P. (Rely on Android Platform)

Sync Manager Framework

App 1 App 2 App 3 App 4

App 1 App 3 App 4 App 2

Page 21: R.A.P. (Rely on Android Platform)

Android Platform

SyncManager

Your App

Service

AbstractThreadedSyncAdapter

Page 22: R.A.P. (Rely on Android Platform)

Synchronization Strategy Selection● On demand

○ E.g. User press button ‘refresh’● Regular interval

○ E.g. Each hour● When network connection available

○ E.g. Sync automatically when connected● When device data changes

○ E.g. Every time my database changes● When server data changes

○ E.g. Every push message received

Page 23: R.A.P. (Rely on Android Platform)

Android Platform

Sync Manager

Your App

Service

AbstractThreadedSyncAdapter

Your app

PerformSync

On demand example

Page 24: R.A.P. (Rely on Android Platform)

Android Platform

Sync Manager

Your App

Service

AbstractThreadedSyncAdapter

Your app

PerformSyncServer push syncYour server

Page 25: R.A.P. (Rely on Android Platform)

AbstractThreadedSyncAdapter

Page 26: R.A.P. (Rely on Android Platform)

Content provider

“Content providers manage access to a structured set of data”

Android developers

Page 27: R.A.P. (Rely on Android Platform)

Android Platform

ContentResolver

Your App

ContentProvider

SQLiteOpenHelper

SQLite

Page 28: R.A.P. (Rely on Android Platform)

Android Platform

ContentResolver

Your App

ContentProvider

SQLiteOpenHelper

SQLite

Your app

Query InsertDelete

Update

Bulk

Page 29: R.A.P. (Rely on Android Platform)

ContentProvider

Page 30: R.A.P. (Rely on Android Platform)

SQLiteOpenHelper

Page 31: R.A.P. (Rely on Android Platform)

Loaders

“Loaders make it easy to asynchronously load data in an activity or fragment”

Android developers

Page 32: R.A.P. (Rely on Android Platform)

Android Platform

LoaderManager

Your App

ContentProvider

SQLiteOpenHelper

SQLite

Fragment | Activityimplements LoaderCallbacks<Cursor>

Query

Page 33: R.A.P. (Rely on Android Platform)

UI thread Background thread

1. getLoaderManager().initLoader(...)

2. onCreateLoader(...)query specific code

4. onLoadFinished(...)swap adapter

3. Execute query on DB

Page 34: R.A.P. (Rely on Android Platform)

LoaderManager.LoaderCallbacks<Cursor>

Page 35: R.A.P. (Rely on Android Platform)

Conclusion

Page 36: R.A.P. (Rely on Android Platform)

Your app

Account Provider Sync Model

Android Platform

Activities & Fragments & Loaders

Page 37: R.A.P. (Rely on Android Platform)
Page 38: R.A.P. (Rely on Android Platform)

Demo time

Page 39: R.A.P. (Rely on Android Platform)

Server side

PLAIN API

POST api/v1/account/new/ Creates new account and returns auth_token

POST api/v1/account/login/ Validates username & password tuple and returns auth_token

AUTHORIZED API

GET api/v1/spots/ Returns spots on the database→ auth_token→ position→ limit