Javier de Pedro López Strengths Experience Senior Android Developer 3 Years professionally 2 Different companies Free time architecture Design Patterns Gradle Code quality @droidpl [email protected] [email protected]
Try & try & fail Pojos Services Sync Adapters Why I did investigate? • I work on an SDK similar to firebase • Should work offline • Should have a simple API • Should be reliable and user friendly Why This matters?
Try & try & fail Why This matters? Pojos Services Sync Adapters Why I did investigate? • Offline improves user experience • No loading times (most of the cases) • App always accesible • Just like magic • Makes your app less error prone • Forces the developer to think more mobile • Say no to: “you always have a good internet connection”
Try & try & fail Why This matters? Pojos Services Sync Adapters Why I did investigate? Using POJOS • Action cancellation • Lifecycle management • Single responsibility principle broken • Messy thread management • Hard to read code • Fast to implement
Try & try & fail Why This matters? Pojos Services Sync Adapters Why I did investigate? Problems using Services • Action cancellation is still a pain • Easy to leak memory • Easy to split in many services • Export to other apps • Easier to handle threading • Possibility to have many processes • Simplified callback system
Try & try & fail Why This matters? Pojos Services Sync Adapters Why I did investigate? Problems using Services • Hard disconnection errors • Sync adapter documentation • Sync adapter configuration (many files) • Too linked to accounts • Uses system tools • Content change notifications • All the benefits from services
Loaders Architecture proposal Job schedulers All together Read Write Loaders Repositories Views/ MVP/ Interactors Loader inits provides data gets notified android lifecycle asks for data Data source
Loader states Architecture proposal Job schedulers All together Read Write Loaders Repositories Started Stopped Reset Can load Can observe Can deliver Can load Can observe Can deliver Can load Can observe Can deliver Stop/Reset Start/Reset Start
Job schedulers Architecture proposal Job schedulers Loaders All together Read Write Repositories Pojo notifies notifies System Scheduler schedule job Preconditions check Sync Service trigger met Sync task run task
Architecture proposal Job schedulers Loaders Overall diagram All together Read Write Repositories Data Repository Notifies Asks for data Loader Inits Provides data System Scheduler Schedule sync Sync Service Sync task Conditions met Run task Changes data Read Write Read Write Views/ MVP/ Interactors Start App SDK write
Post repository: all posts @WorkerThread public List posts() { Response> postsResponse = mPostService.posts().execute(); if (postsResponse.isSuccessful()) { List posts = postsResponse.body(); mPostDao.deleteAll(); mPostDao.save(posts); } return mPostDao.posts(); } datasource
Conclusions Offline matters because UX matters It is part of the architecture Not so much effort with the right choice Unique dataflow Don’t reinvent the wheel - Android has it -