R.A.P.
Rely on Android Platform
DISCLAIMER
@ibai_iturricha
● NFC
● Android
● Django
CTO en Aditium
Why should I
RAP?
My app …
manages user accounts
loads/pulls data from/to server
works without connection
and ...
I want to be a winner!
Decouple authentication from business logic
Isolate synchronization strategy
Offline first
Modular UI Components
http://rapgenius.com/discussions/12681-New-version-of-the-last-supper
Time to RAP homies!
Android Platform crew
Account Manager manages user credentials
Sync Manager keeps data up to date
Content Provider stores ...
Account Manager
“Account Manager provides access to a
centralized registry of the user's online
accounts”
Android develope...
Android Platform
Account
Manager
Your App
Service
AbstractAccountAuthenticator
AccountAuthenticatorActivity
Android Platform
Account
Manager
Your App
Service
AbstractAccountAuthenticator
AccountAuthenticatorActivity
Your app
Add a...
AbstractAccountAuthenticator
Sync
Manager/Adapter
“The ability of the system to
help you synchronize
remote and local content”
Virgil Dobjanschi (Googl...
App 1 App 2 App 3 App 4
Perform a sync → Network request, parceling, DB operations, etc...
Sepherd wanted!
Sync Manager Framework
App 1 App 2 App 3 App 4
App 1 App 3 App 4 App 2
Android Platform
Sync
Manager
Your App
Service
AbstractThreadedSyncAdapter
Synchronization Strategy Selection
● On demand
○ E.g. User press button ‘refresh’
● Regular interval
○ E.g. Each hour
● Wh...
Android Platform
Sync
Manager
Your App
Service
AbstractThreadedSyncAdapter
Your app
PerformSync
On demand example
Android Platform
Sync
Manager
Your App
Service
AbstractThreadedSyncAdapter
Your app
PerformSync
Server push sync
Your serv...
AbstractThreadedSyncAdapter
Content provider
“Content providers manage access
to a structured set of data”
Android developers
Android Platform
Content
Resolver
Your App
ContentProvider
SQLiteOpenHelper
SQLite
Android Platform
Content
Resolver
Your App
ContentProvider
SQLiteOpenHelper
SQLite
Your app
Query Insert
Delete
Update
Bulk
ContentProvider
SQLiteOpenHelper
Loaders
“Loaders make it easy to asynchronously
load data in an activity or fragment”
Android developers
Android Platform
Loader
Manager
Your App
ContentProvider
SQLiteOpenHelper
SQLite
Fragment | Activity
implements LoaderCall...
UI thread Background thread
1. getLoaderManager().initLoader(...)
2. onCreateLoader(...)
query specific code
4. onLoadFini...
LoaderManager.LoaderCallbacks<Cursor>
Conclusion
Your app
Account Provider Sync Model
Android Platform
Activities & Fragments & Loaders
Demo time
Server side
PLAIN API
POST api/v1/account/new/ Creates new account and returns auth_token
POST api/v1/account/login/ Valid...
R.A.P. (Rely on Android Platform)
Upcoming SlideShare
Loading in …5
×

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

1,563 views

Published on

Slides for droidcon spain 2014.

Published in: Technology
1 Comment
1 Like
Statistics
Notes
No Downloads
Views
Total views
1,563
On SlideShare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
12
Comments
1
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 1. R.A.P. Rely on Android Platform
  2. 2. DISCLAIMER
  3. 3. @ibai_iturricha ● NFC ● Android ● Django CTO en Aditium
  4. 4. Why should I RAP?
  5. 5. My app … manages user accounts loads/pulls data from/to server works without connection and ...
  6. 6. I want to be a winner!
  7. 7. Decouple authentication from business logic
  8. 8. Isolate synchronization strategy
  9. 9. Offline first
  10. 10. Modular UI Components
  11. 11. http://rapgenius.com/discussions/12681-New-version-of-the-last-supper Time to RAP homies!
  12. 12. Android Platform crew Account Manager manages user credentials Sync Manager keeps data up to date Content Provider stores structured data Loaders make data available
  13. 13. Account Manager “Account Manager provides access to a centralized registry of the user's online accounts” Android developers
  14. 14. Android Platform Account Manager Your App Service AbstractAccountAuthenticator AccountAuthenticatorActivity
  15. 15. Android Platform Account Manager Your App Service AbstractAccountAuthenticator AccountAuthenticatorActivity Your app Add account Get auhtToken Delete account
  16. 16. AbstractAccountAuthenticator
  17. 17. Sync Manager/Adapter “The ability of the system to help you synchronize remote and local content” Virgil Dobjanschi (Google IO 201)
  18. 18. App 1 App 2 App 3 App 4 Perform a sync → Network request, parceling, DB operations, etc...
  19. 19. Sepherd wanted!
  20. 20. Sync Manager Framework App 1 App 2 App 3 App 4 App 1 App 3 App 4 App 2
  21. 21. Android Platform Sync Manager Your App Service AbstractThreadedSyncAdapter
  22. 22. 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
  23. 23. Android Platform Sync Manager Your App Service AbstractThreadedSyncAdapter Your app PerformSync On demand example
  24. 24. Android Platform Sync Manager Your App Service AbstractThreadedSyncAdapter Your app PerformSync Server push sync Your server
  25. 25. AbstractThreadedSyncAdapter
  26. 26. Content provider “Content providers manage access to a structured set of data” Android developers
  27. 27. Android Platform Content Resolver Your App ContentProvider SQLiteOpenHelper SQLite
  28. 28. Android Platform Content Resolver Your App ContentProvider SQLiteOpenHelper SQLite Your app Query Insert Delete Update Bulk
  29. 29. ContentProvider
  30. 30. SQLiteOpenHelper
  31. 31. Loaders “Loaders make it easy to asynchronously load data in an activity or fragment” Android developers
  32. 32. Android Platform Loader Manager Your App ContentProvider SQLiteOpenHelper SQLite Fragment | Activity implements LoaderCallbacks<Cursor> Query
  33. 33. UI thread Background thread 1. getLoaderManager().initLoader(...) 2. onCreateLoader(...) query specific code 4. onLoadFinished(...) swap adapter 3. Execute query on DB
  34. 34. LoaderManager.LoaderCallbacks<Cursor>
  35. 35. Conclusion
  36. 36. Your app Account Provider Sync Model Android Platform Activities & Fragments & Loaders
  37. 37. Demo time
  38. 38. 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

×