to provide and serve content royi benyossef

36
To provide & serve… by Royi Benyossef (+royiby). Content!

Upload: amirlazarovich

Post on 13-Jul-2015

144 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: To provide and serve content   royi benyossef

To provide & serve…

by Royi Benyossef (+royiby).

Content!

Page 2: To provide and serve content   royi benyossef

What do we want?!

To provide & serve… content! by Royi Benyossef (+royiby).

Page 3: To provide and serve content   royi benyossef

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).

Page 4: To provide and serve content   royi benyossef

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).

Page 5: To provide and serve content   royi benyossef

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).

Page 6: To provide and serve content   royi benyossef

What do we want?!

• Search the data quickly and easily.

To provide & serve… content! by Royi Benyossef (+royiby).

Page 7: To provide and serve content   royi benyossef

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).

Page 8: To provide and serve content   royi benyossef

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).

Page 9: To provide and serve content   royi benyossef

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).

Page 10: To provide and serve content   royi benyossef

How can we get it?!

To provide & serve… content! by Royi Benyossef (+royiby).

1. ContentProvider

Page 11: To provide and serve content   royi benyossef

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).

Page 12: To provide and serve content   royi benyossef

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).

Page 13: To provide and serve content   royi benyossef

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).

Page 14: To provide and serve content   royi benyossef

Item.java – initial state.

To provide & serve… content! by Royi Benyossef (+royiby).

Page 15: To provide and serve content   royi benyossef

ContentProviders – initial state.

To provide & serve… content! by Royi Benyossef (+royiby).

Page 16: To provide and serve content   royi benyossef

ContentProviders – DB columns

To provide & serve… content! by Royi Benyossef (+royiby).

Page 17: To provide and serve content   royi benyossef

ContentProviders–SQLite DB helper

To provide & serve… content! by Royi Benyossef (+royiby).

Page 18: To provide and serve content   royi benyossef

ContentProviders item #2

To provide & serve… content! by Royi Benyossef (+royiby).

Page 19: To provide and serve content   royi benyossef

ContentProviders–Demo.

• Objectives:– Crum methods.

– Loader methods.

– Application demo.

To provide & serve… content! by Royi Benyossef (+royiby).

Page 20: To provide and serve content   royi benyossef

How can we get it?!

To provide & serve… content! by Royi Benyossef (+royiby).

2. ORM

Page 21: To provide and serve content   royi benyossef

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).

Page 22: To provide and serve content   royi benyossef

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).

Page 23: To provide and serve content   royi benyossef

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).

Page 24: To provide and serve content   royi benyossef

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).

Page 25: To provide and serve content   royi benyossef

3rd party ORM - ORMLite demo.

• Objectives:– Integration simplicity.

– Crum methods.

– Application demo

To provide & serve… content! by Royi Benyossef (+royiby).

Page 26: To provide and serve content   royi benyossef

To provide & serve… content! by Royi Benyossef (+royiby).

How can we get it?!

To provide & serve… content! by Royi Benyossef (+royiby).

3. Custom handler

Page 27: To provide and serve content   royi benyossef

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).

Page 28: To provide and serve content   royi benyossef

Custom handler - advantages

• Efficiency.

• In-depth knowledge of functionality.

• Lower level API access.

To provide & serve… content! by Royi Benyossef (+royiby).

Page 29: To provide and serve content   royi benyossef

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).

Page 30: To provide and serve content   royi benyossef

Custom handler – demo.

To provide & serve… content! by Royi Benyossef (+royiby).

Page 31: To provide and serve content   royi benyossef

Lets summarize:

To provide & serve… content! by Royi Benyossef (+royiby).

Page 32: To provide and serve content   royi benyossef

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).

Page 33: To provide and serve content   royi benyossef

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).

Page 34: To provide and serve content   royi benyossef

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).

Page 35: To provide and serve content   royi benyossef

Success!

To provide & serve… content! by Royi Benyossef (+royiby).

Page 36: To provide and serve content   royi benyossef

I hope you liked it.

by Royi Benyossef (+royiby).

Thank you for listening.