SlideShare a Scribd company logo
Android REST Client Architecture
About me
Independent Android Consultant and Trainer
Co-founder of IAA
GDG & GDE
+Ran Nachmany
Rest Architecture
 Client and server
 Client send request get or change resource.
 Twitter, facebook, Google, flight schedule etc.
The quick & dirty approach
              Activity               Adapter




   Thread - worker

    Rest Method          Processor




                                     Memory
The quick & dirty and wrong approach
              Activity               Adapter




   Thread - worker

    Rest Method          Processor




                                     Memory
Android Laws

 Foreground Apps.
   must have the resources they need
 Visible activity or running service.
   Should keep running.
   As long as it does not break #1
 Background Apps
   kept in memory to reduce start up and latency time.
   As long as it does not break #1 or #2.
Implications:

 Android may (and will) shut down your process.
 Background apps should be ready to die
   Handle onPause() and onStop().
 Background apps should be “thin”.
   Being good android citizen increases your chances to live
   longer.
The quick & dirty and wrong approach

 Killed during transaction
   Request may or may not executed on server side.


 No persistence data
   High latency.
   Waste of bandwidth.
   Waste of battery
Solution #1: Service API
Service

 Service is designed to run in the background.
 Has no user interface.
 Runs on main thread (i.e. UI thread)
   You still need to create a worker thread.
Service
             Activity




          Data Processor   Storage


           Rest Method


            Service
Activity ↔ Service interface

 Starting the service:
   Activity.startService(Intent I).


 Initiating transactions and getting results:
   Binder interface.
   Intent interface.
Activity ↔ Service interface

 Start Service
Binder Interface - Activity
Binder Interface - Activity
Binder Interface – Service side
Intent Interface – Activity side
Intent Interface – Service side
Service
             Activity




          Data Processor   Storage


           Rest Method


            Service
Data Processor
 Holds a “mirror” of the data in the server.
 Runs before and after each transaction.

 Before Post / Put:
   Prepare transaction data
   Create DB row with status “updating”
 After Post / Put:
   Clear the “updating” status.
Data Processor

 Before Delete;
   Set status to “DELETING”
 After Delete:
   Delete DB row.


 Before GET
 After GET
   Update DB
Service
             Activity


            Wrapper




          Data Processor   Storage


           Rest Method


            Service
Service Wrapper
 Singletone.
 Exposes simple async API to be used by UI.
 Upon service request:
   Check if method is already pending.
   Create intent.
   Generate req id.
   Hold binder.
   Return Req id.
 Handle callback from the service.
Handling service callback - Activity

 Activity has its own lifecycle.
   Activity is still active when the response arrives.
   Activity is paused, resumed and then the response
   arrives.
   Activity is paused with the response arrives, and than
   resumed.
 Adapter.notifyDataSetChanged() when needed.
Solution #2: Content Provider
Content Provider

 Mechanism to share /transfer data across boundries.
 Usually used to share data between apps.
Activity & Cursor Adapter



           Content Provider


  Wrapper


 Service

Data Processor


 Rest Method
Activity & Cursor Adapter

1. Query (insert /
update/ delete)
                                Content Provider


                       Wrapper


                      Service

                     Data Processor


                      Rest Method
Activity & Cursor Adapter

1. Query (insert /
update/ delete)
                                Content Provider
2. Start (intent)
                       Wrapper


                      Service

                     Data Processor


                      Rest Method
Activity & Cursor Adapter

1. Query (insert /
update/ delete)
                                Content Provider
2. Start (intent)
                       Wrapper
3. Start Service
                      Service

                     Data Processor


                      Rest Method
Activity & Cursor Adapter

1. Query (insert /
update/ delete)
                                Content Provider
2. Start (intent)
                       Wrapper
3. Start Service
                      Service

                     Data Processor
4. Execute method
                      Rest Method
Activity & Cursor Adapter

1. Query (insert /
update/ delete)
                                Content Provider
2. Start (intent)
                       Wrapper
3. Start Service
                      Service

                     Data Processor
4. Execute method                 5. Process respons
                      Rest Method
Activity & Cursor Adapter

1. Query (insert /
update/ delete)
                                Content Provider
2. Start (intent)
                       Wrapper
3. Start Service
                                                       6. Insert/ update/
                      Service                          delete

                     Data Processor
4. Execute method                 5. Process respons
                      Rest Method
Activity & Cursor Adapter

1. Query (insert /              7. Notify Content
update/ delete)                 Observer
                                Content Provider
2. Start (intent)
                       Wrapper
3. Start Service
                                                       6. Insert/ update/
                      Service                          delete

                     Data Processor
4. Execute method                 5. Process respons
                      Rest Method
Activity & Cursor Adapter

1. Query (insert /              7. Notify Content       8. Query
update/ delete)                 Observer
                                Content Provider
2. Start (intent)
                       Wrapper
3. Start Service
                                                       6. Insert/ update/
                      Service                          delete

                     Data Processor
4. Execute method                 5. Process respons
                      Rest Method
Solution #3: Content Provider + Sync
Adapter
Activity & Cursor Adapter



         Content Provider


Sync Adapter




Data Processor


 Rest Method
Summary

 Don't implement REST method in Activity / UI
 layer.
 Long running ops should run inside a service
   And don't forget worker thread.
 Persist early, persist often
   Don't download what you already know.
   Don't make me go crazy.
 Sync adapter for non critical BG operations.
Thank You

More Related Content

What's hot

SVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java RuntimeSVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java Runtime
Van Riper
 
Is Serverless The New Swiss Cheese?
Is Serverless The New Swiss Cheese?Is Serverless The New Swiss Cheese?
Is Serverless The New Swiss Cheese?
Chase Douglas
 
How to do Memory Optimizations in Android
How to do Memory Optimizations in AndroidHow to do Memory Optimizations in Android
How to do Memory Optimizations in Android
Singsys Pte Ltd
 
Serverless lessons learned #3 reserved concurrency
Serverless lessons learned #3 reserved concurrencyServerless lessons learned #3 reserved concurrency
Serverless lessons learned #3 reserved concurrency
Maik Wiesmüller
 
Serverless lessons learned #1 custom sdk timeouts
Serverless lessons learned #1 custom sdk timeoutsServerless lessons learned #1 custom sdk timeouts
Serverless lessons learned #1 custom sdk timeouts
Maik Wiesmüller
 
Snappy ubuntu+m2m labscharm
Snappy ubuntu+m2m labscharmSnappy ubuntu+m2m labscharm
Snappy ubuntu+m2m labscharm
supportm2mlabs
 
Serverless lessons learned #4 circuit breaker
Serverless lessons learned #4 circuit breakerServerless lessons learned #4 circuit breaker
Serverless lessons learned #4 circuit breaker
Maik Wiesmüller
 
Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?
Anthony Brown
 
Aero app updates how to v1.1510.12
Aero app updates how to v1.1510.12Aero app updates how to v1.1510.12
Aero app updates how to v1.1510.12
5101AVNREGT
 
Serverless lessons learned #2 dead letter queues
Serverless lessons learned #2 dead letter queuesServerless lessons learned #2 dead letter queues
Serverless lessons learned #2 dead letter queues
Maik Wiesmüller
 
Automating with FME 2019
Automating with FME 2019Automating with FME 2019
Automating with FME 2019
Safe Software
 
Webinar Getting Started with FME Desktop: Your Burning Questions Answered
 Webinar Getting Started with FME Desktop: Your Burning Questions Answered Webinar Getting Started with FME Desktop: Your Burning Questions Answered
Webinar Getting Started with FME Desktop: Your Burning Questions Answered
Safe Software
 

What's hot (12)

SVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java RuntimeSVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java Runtime
 
Is Serverless The New Swiss Cheese?
Is Serverless The New Swiss Cheese?Is Serverless The New Swiss Cheese?
Is Serverless The New Swiss Cheese?
 
How to do Memory Optimizations in Android
How to do Memory Optimizations in AndroidHow to do Memory Optimizations in Android
How to do Memory Optimizations in Android
 
Serverless lessons learned #3 reserved concurrency
Serverless lessons learned #3 reserved concurrencyServerless lessons learned #3 reserved concurrency
Serverless lessons learned #3 reserved concurrency
 
Serverless lessons learned #1 custom sdk timeouts
Serverless lessons learned #1 custom sdk timeoutsServerless lessons learned #1 custom sdk timeouts
Serverless lessons learned #1 custom sdk timeouts
 
Snappy ubuntu+m2m labscharm
Snappy ubuntu+m2m labscharmSnappy ubuntu+m2m labscharm
Snappy ubuntu+m2m labscharm
 
Serverless lessons learned #4 circuit breaker
Serverless lessons learned #4 circuit breakerServerless lessons learned #4 circuit breaker
Serverless lessons learned #4 circuit breaker
 
Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?Writing a Search Engine. How hard could it be?
Writing a Search Engine. How hard could it be?
 
Aero app updates how to v1.1510.12
Aero app updates how to v1.1510.12Aero app updates how to v1.1510.12
Aero app updates how to v1.1510.12
 
Serverless lessons learned #2 dead letter queues
Serverless lessons learned #2 dead letter queuesServerless lessons learned #2 dead letter queues
Serverless lessons learned #2 dead letter queues
 
Automating with FME 2019
Automating with FME 2019Automating with FME 2019
Automating with FME 2019
 
Webinar Getting Started with FME Desktop: Your Burning Questions Answered
 Webinar Getting Started with FME Desktop: Your Burning Questions Answered Webinar Getting Started with FME Desktop: Your Burning Questions Answered
Webinar Getting Started with FME Desktop: Your Burning Questions Answered
 

Similar to Androd rest client architecture

MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
Jitendra Bafna
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
Muhammad Sajid
 
Software performance testing_overview
Software performance testing_overviewSoftware performance testing_overview
Software performance testing_overviewRohan Bhattarai
 
Netflix conductor
Netflix conductorNetflix conductor
Netflix conductor
Viren Baraiya
 
Door to perfomance testing
Door to perfomance testingDoor to perfomance testing
Door to perfomance testing
Dharshana Kasun Warusavitharana
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012
Droidcon Eastern Europe
 
Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...
Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...
Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...
Codemotion
 
Super simple introduction to REST-APIs (2nd version)
Super simple introduction to REST-APIs (2nd version)Super simple introduction to REST-APIs (2nd version)
Super simple introduction to REST-APIs (2nd version)
Patrick Savalle
 
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
IRJET Journal
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
Owain Lewis
 
E property project documentation
E property project documentationE property project documentation
E property project documentationMusakkhir Sayyed
 
People soft workflow by surya 2
People soft workflow by surya 2People soft workflow by surya 2
People soft workflow by surya 2meghamystic
 
Advanced java+JDBC+Servlet
Advanced java+JDBC+ServletAdvanced java+JDBC+Servlet
Advanced java+JDBC+Servlet
Anuj Singh Rajput
 
Day02 a pi.
Day02   a pi.Day02   a pi.
Day02 a pi.
ABDEL RAHMAN KARIM
 
Android app performance
Android app performanceAndroid app performance
Android app performance
Saksham Keshri
 
IT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNGIT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNG
DataArt
 
Building a microservice architecture for a 100mio# revenue company
Building a microservice architecture for a 100mio# revenue companyBuilding a microservice architecture for a 100mio# revenue company
Building a microservice architecture for a 100mio# revenue company
ProjectAcom
 
Rest assured
Rest assuredRest assured
Rest assured
Varun Deshpande
 
Modelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST urlModelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST url
Xebia IT Architects
 
Workflow On The Fly Monitoring Solution
Workflow On The Fly Monitoring SolutionWorkflow On The Fly Monitoring Solution
Workflow On The Fly Monitoring SolutionRoman Agaev
 

Similar to Androd rest client architecture (20)

MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
MuleSoft Surat Virtual Meetup#21 - MuleSoft API and RAML Design Best Practice...
 
Data Transfer between Activities & Databases
Data Transfer between Activities & DatabasesData Transfer between Activities & Databases
Data Transfer between Activities & Databases
 
Software performance testing_overview
Software performance testing_overviewSoftware performance testing_overview
Software performance testing_overview
 
Netflix conductor
Netflix conductorNetflix conductor
Netflix conductor
 
Door to perfomance testing
Door to perfomance testingDoor to perfomance testing
Door to perfomance testing
 
Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012Android rest client applications-services approach @Droidcon Bucharest 2012
Android rest client applications-services approach @Droidcon Bucharest 2012
 
Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...
Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...
Search on the fly: how to lighten your Big Data - Simona Russo, Auro Rolle - ...
 
Super simple introduction to REST-APIs (2nd version)
Super simple introduction to REST-APIs (2nd version)Super simple introduction to REST-APIs (2nd version)
Super simple introduction to REST-APIs (2nd version)
 
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
IRJET- Real Time Monitoring of Servers with Prometheus and Grafana for High A...
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
E property project documentation
E property project documentationE property project documentation
E property project documentation
 
People soft workflow by surya 2
People soft workflow by surya 2People soft workflow by surya 2
People soft workflow by surya 2
 
Advanced java+JDBC+Servlet
Advanced java+JDBC+ServletAdvanced java+JDBC+Servlet
Advanced java+JDBC+Servlet
 
Day02 a pi.
Day02   a pi.Day02   a pi.
Day02 a pi.
 
Android app performance
Android app performanceAndroid app performance
Android app performance
 
IT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNGIT talk: Как я перестал бояться и полюбил TestNG
IT talk: Как я перестал бояться и полюбил TestNG
 
Building a microservice architecture for a 100mio# revenue company
Building a microservice architecture for a 100mio# revenue companyBuilding a microservice architecture for a 100mio# revenue company
Building a microservice architecture for a 100mio# revenue company
 
Rest assured
Rest assuredRest assured
Rest assured
 
Modelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST urlModelling RESTful applications – Why should I not use verbs in REST url
Modelling RESTful applications – Why should I not use verbs in REST url
 
Workflow On The Fly Monitoring Solution
Workflow On The Fly Monitoring SolutionWorkflow On The Fly Monitoring Solution
Workflow On The Fly Monitoring Solution
 

Recently uploaded

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Paige Cruz
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
DianaGray10
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
Adtran
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
Neo4j
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 

Recently uploaded (20)

GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdfObservability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
Observability Concepts EVERY Developer Should Know -- DeveloperWeek Europe.pdf
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1Communications Mining Series - Zero to Hero - Session 1
Communications Mining Series - Zero to Hero - Session 1
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Pushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 daysPushing the limits of ePRTC: 100ns holdover for 100 days
Pushing the limits of ePRTC: 100ns holdover for 100 days
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
GraphSummit Singapore | Graphing Success: Revolutionising Organisational Stru...
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 

Androd rest client architecture

  • 1. Android REST Client Architecture
  • 2. About me Independent Android Consultant and Trainer Co-founder of IAA GDG & GDE +Ran Nachmany
  • 3. Rest Architecture Client and server Client send request get or change resource. Twitter, facebook, Google, flight schedule etc.
  • 4. The quick & dirty approach Activity Adapter Thread - worker Rest Method Processor Memory
  • 5. The quick & dirty and wrong approach Activity Adapter Thread - worker Rest Method Processor Memory
  • 6. Android Laws Foreground Apps. must have the resources they need Visible activity or running service. Should keep running. As long as it does not break #1 Background Apps kept in memory to reduce start up and latency time. As long as it does not break #1 or #2.
  • 7. Implications: Android may (and will) shut down your process. Background apps should be ready to die Handle onPause() and onStop(). Background apps should be “thin”. Being good android citizen increases your chances to live longer.
  • 8. The quick & dirty and wrong approach Killed during transaction Request may or may not executed on server side. No persistence data High latency. Waste of bandwidth. Waste of battery
  • 9.
  • 11. Service Service is designed to run in the background. Has no user interface. Runs on main thread (i.e. UI thread) You still need to create a worker thread.
  • 12. Service Activity Data Processor Storage Rest Method Service
  • 13. Activity ↔ Service interface Starting the service: Activity.startService(Intent I). Initiating transactions and getting results: Binder interface. Intent interface.
  • 14. Activity ↔ Service interface Start Service
  • 15. Binder Interface - Activity
  • 16. Binder Interface - Activity
  • 17. Binder Interface – Service side
  • 18. Intent Interface – Activity side
  • 19. Intent Interface – Service side
  • 20. Service Activity Data Processor Storage Rest Method Service
  • 21. Data Processor Holds a “mirror” of the data in the server. Runs before and after each transaction. Before Post / Put: Prepare transaction data Create DB row with status “updating” After Post / Put: Clear the “updating” status.
  • 22. Data Processor Before Delete; Set status to “DELETING” After Delete: Delete DB row. Before GET After GET Update DB
  • 23. Service Activity Wrapper Data Processor Storage Rest Method Service
  • 24. Service Wrapper Singletone. Exposes simple async API to be used by UI. Upon service request: Check if method is already pending. Create intent. Generate req id. Hold binder. Return Req id. Handle callback from the service.
  • 25. Handling service callback - Activity Activity has its own lifecycle. Activity is still active when the response arrives. Activity is paused, resumed and then the response arrives. Activity is paused with the response arrives, and than resumed. Adapter.notifyDataSetChanged() when needed.
  • 27. Content Provider Mechanism to share /transfer data across boundries. Usually used to share data between apps.
  • 28. Activity & Cursor Adapter Content Provider Wrapper Service Data Processor Rest Method
  • 29. Activity & Cursor Adapter 1. Query (insert / update/ delete) Content Provider Wrapper Service Data Processor Rest Method
  • 30. Activity & Cursor Adapter 1. Query (insert / update/ delete) Content Provider 2. Start (intent) Wrapper Service Data Processor Rest Method
  • 31. Activity & Cursor Adapter 1. Query (insert / update/ delete) Content Provider 2. Start (intent) Wrapper 3. Start Service Service Data Processor Rest Method
  • 32. Activity & Cursor Adapter 1. Query (insert / update/ delete) Content Provider 2. Start (intent) Wrapper 3. Start Service Service Data Processor 4. Execute method Rest Method
  • 33. Activity & Cursor Adapter 1. Query (insert / update/ delete) Content Provider 2. Start (intent) Wrapper 3. Start Service Service Data Processor 4. Execute method 5. Process respons Rest Method
  • 34. Activity & Cursor Adapter 1. Query (insert / update/ delete) Content Provider 2. Start (intent) Wrapper 3. Start Service 6. Insert/ update/ Service delete Data Processor 4. Execute method 5. Process respons Rest Method
  • 35. Activity & Cursor Adapter 1. Query (insert / 7. Notify Content update/ delete) Observer Content Provider 2. Start (intent) Wrapper 3. Start Service 6. Insert/ update/ Service delete Data Processor 4. Execute method 5. Process respons Rest Method
  • 36. Activity & Cursor Adapter 1. Query (insert / 7. Notify Content 8. Query update/ delete) Observer Content Provider 2. Start (intent) Wrapper 3. Start Service 6. Insert/ update/ Service delete Data Processor 4. Execute method 5. Process respons Rest Method
  • 37. Solution #3: Content Provider + Sync Adapter
  • 38. Activity & Cursor Adapter Content Provider Sync Adapter Data Processor Rest Method
  • 39. Summary Don't implement REST method in Activity / UI layer. Long running ops should run inside a service And don't forget worker thread. Persist early, persist often Don't download what you already know. Don't make me go crazy. Sync adapter for non critical BG operations.