to provide and serve content royi benyossef
TRANSCRIPT
To provide & serve…
by Royi Benyossef (+royiby).
Content!
What do we want?!
To provide & serve… content! by Royi Benyossef (+royiby).
What do we want?!
• Save the data to disk.
• Store a large amount of data.
• Search the data quickly and easily.
• Serve your client when they’re offline.
• Support custom access in special cases.
• Supply data access to external processes.
To provide & serve… content! by Royi Benyossef (+royiby).
What do we want?!
• Save the data to disk.– Save “favorite data bits” for next time.
– Have a “hard copy” backup.
To provide & serve… content! by Royi Benyossef (+royiby).
What do we want?!
• Store a large amount of data.
–Theoretically, as much as the size of the device’s
available storage (don’t try this at home).
To provide & serve… content! by Royi Benyossef (+royiby).
What do we want?!
• Search the data quickly and easily.
To provide & serve… content! by Royi Benyossef (+royiby).
What do we want?!
• Serve your client when they’re offline.– Don’t rely on constant internet connection.
– “Mobile client rarely accepts disappointment a second time”
To provide & serve… content! by Royi Benyossef (+royiby).
What do we want?!
• Support custom access in special cases.– Sometimes you have to do something which isn’t a common-
practice and you need lower level support and control.
To provide & serve… content! by Royi Benyossef (+royiby).
What do we want?!
• Supply data access to external processes.
– Create several apps with 1 data source.
– Externalize your data to 3rd party apps.
To provide & serve… content! by Royi Benyossef (+royiby).
How can we get it?!
To provide & serve… content! by Royi Benyossef (+royiby).
1. ContentProvider
ContentProviders – what are they?
• A part of the Android API.
• A tool for managing access to a central
repository of data.
• Data repositories could be of any kind:
– SQLite database.
– text and binary files.
To provide & serve… content! by Royi Benyossef (+royiby).
ContentProviders – advantages:
• Android native support:– what’s working now will not break in updates, guaranteed.
– Data externalization to other applications supported.
• Structured programming – the tools are outlined in
the API.
• Flexible – if special implementation is required, just
access the SQLite or file APIs.
To provide & serve… content! by Royi Benyossef (+royiby).
ContentProviders – disadvantages:
• A lot of implementation is required to function.
• An understanding of the lower APIs is required.
To provide & serve… content! by Royi Benyossef (+royiby).
Item.java – initial state.
To provide & serve… content! by Royi Benyossef (+royiby).
ContentProviders – initial state.
To provide & serve… content! by Royi Benyossef (+royiby).
ContentProviders – DB columns
To provide & serve… content! by Royi Benyossef (+royiby).
ContentProviders–SQLite DB helper
To provide & serve… content! by Royi Benyossef (+royiby).
ContentProviders item #2
To provide & serve… content! by Royi Benyossef (+royiby).
ContentProviders–Demo.
• Objectives:– Crum methods.
– Loader methods.
– Application demo.
To provide & serve… content! by Royi Benyossef (+royiby).
How can we get it?!
To provide & serve… content! by Royi Benyossef (+royiby).
2. ORM
What is ORM?
• Object-Relational mapping is a design pattern used to
convert data between incompatible type system in OOP, A
POJO to SQLite record situation is a classic example.
• ORM libraries are widely used on server-side programming
since it saves the time to build a specific database system.
To provide & serve… content! by Royi Benyossef (+royiby).
ORM in Android
• There’s no native ORM support in Android.
• Using ORM requires the use of a 3rd party library.
• Examples of prevalent libraries:
– http://greendao-orm.com/
– http://ormlite.com/
To provide & serve… content! by Royi Benyossef (+royiby).
3rd party ORM advantages:
• Easy integration.
• Almost no development needed.
• Works in a similar way as server ORMs
(especially if you use the same library for the
Android & server).
To provide & serve… content! by Royi Benyossef (+royiby).
3rd party ORM disadvantages:
• Not supported by the API:– Might “break” by new releases.
– Data sharing between applications is almost impossible.
• inflexible; almost any special case requires duplicate
implementation.
To provide & serve… content! by Royi Benyossef (+royiby).
3rd party ORM - ORMLite demo.
• Objectives:– Integration simplicity.
– Crum methods.
– Application demo
To provide & serve… content! by Royi Benyossef (+royiby).
To provide & serve… content! by Royi Benyossef (+royiby).
How can we get it?!
To provide & serve… content! by Royi Benyossef (+royiby).
3. Custom handler
Custom handler?
• Create your own database access system.
• Create background threads with ThreadPool or
Thread for database CRUD.
To provide & serve… content! by Royi Benyossef (+royiby).
Custom handler - advantages
• Efficiency.
• In-depth knowledge of functionality.
• Lower level API access.
To provide & serve… content! by Royi Benyossef (+royiby).
Custom handler - disadvantages
• Longer development time.
• No data sharing.
• Redundant code.
• Stumbling on to problems that were fixed by
someone else before.
To provide & serve… content! by Royi Benyossef (+royiby).
Custom handler – demo.
To provide & serve… content! by Royi Benyossef (+royiby).
Lets summarize:
To provide & serve… content! by Royi Benyossef (+royiby).
How can we get it?
Create a custom database handler:
• Save the data to disk.
• Store a large amount of data.
• Search the data quickly and easily.
• Serve your client when they’re offline.
• Support custom access in special cases.
• Supply data access to external processes.
To provide & serve… content! by Royi Benyossef (+royiby).
How can we get it?
Use 3rd party ORM:
• Save the data to disk.
• Store a large amount of data.
• Search the data quickly and easily.
• Serve your client when they’re offline.
• Support custom access in special cases.
• Supply data access to external processes.
To provide & serve… content! by Royi Benyossef (+royiby).
How can we get it?
Use Android’s content providers:
• Save the data to disk.
• Store a large amount of data.
• Search the data quickly and easily.
• Serve your client when they’re offline.
• Support custom access in special cases.
• Supply data access to external processes.
To provide & serve… content! by Royi Benyossef (+royiby).
Success!
To provide & serve… content! by Royi Benyossef (+royiby).
I hope you liked it.
by Royi Benyossef (+royiby).
Thank you for listening.