Mar 21 | 3:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Mar 21 | 4:15 PM |
Fabio M. | has entered the room |
Mark M. |
hello, Fabio!
|
Mark M. |
how can I help you today?
|
Fabio M. |
hi mark :)
|
Mark M. |
do you have a question?
|
Fabio M. |
Yes, i'm a beginner and i'm starting to work on db access trough sqlite. I read your chapter and tutorial on this matter. My concern is about what is the best way to implement the db access through a single activity and multiple fragments requiring db access.
|
Mar 21 | 4:20 PM |
Mark M. |
I would have some sort of data manager class be the access point to the database
|
Fabio M. |
Is it better to setup a class db helper which calls fragment through callbacks or implementing asynctask in fragments?
|
Mark M. |
I would lean towards using your first option
|
Mark M. |
have a centralized class that handles your data access, threading, caching, etc.
|
Mark M. |
the activity can set up the instance of that class and make it available to the fragments
|
Fabio M. |
Ok just as you did in the epublite?
|
Fabio M. |
So, in general,is better using Threads instead of asynctask for db access
|
Mark M. |
in EmPubLite, I went with the model fragment approach
|
Mark M. |
in a single-activity app, a model fragment might be fine for your data access
|
Mark M. |
sorry, let me rephrase that
|
Mark M. |
in EmPubLite, I demonstrated two approaches
|
Mark M. |
for the main EmPubLite activity, I used a model fragment for data access, though in that case it was not SQLite, but book information
|
Mark M. |
for the notes, I delegated the threading and data access to the DatabaseHelper subclass of SQLiteOpenHelper
|
Mark M. |
in both cases, the UI-related classes (the activity and regular fragments) did not handle threading or the actual I/O
|
Mar 21 | 4:25 PM |
Mark M. |
whether you use regular threads or AsyncTask or RxAndroid or something else is really up to you
|
Fabio M. |
Ok, think i got it :)
|
Mark M. |
they each have their pros and cons
|
Fabio M. |
Ok, thanks a lot for your time. Keep up with this work, i'ma really happy subscriber
|
Mark M. |
you are very welcome!
|
Fabio M. |
Have a nice day
|
Mark M. |
you too!
|
Mar 21 | 4:40 PM |
Fabio M. | has left the room |
Mar 21 | 4:55 PM |
Albert | has entered the room |
Mark M. |
hello, Albert!
|
Mark M. |
how can I help you today?
|
Albert |
hi. thanks. i don't have a specific question today. just thought i'd check in to the chat room and see how it works. haven't visited this before.
|
Mark M. |
mostly, the chat room is lightly populated
|
Albert |
not sure -- is that an ok way to participate?
|
Mark M. |
people ask questions, then head out
|
Albert |
ah. ok.
|
Mark M. |
you can see transcripts of past chats at: https://commonsware.com/office-hours/
|
Mar 21 | 5:00 PM |
Albert |
thanks. i'll take a look at those then. best regards.
|
Mark M. |
I'll be posting the transcript from today's chat (somebody was here earlier) shortly
|
Mark M. |
FWIW, the next chat is tomorrow at 7:30pm US Eastern
|
Mark M. |
but, for now, that's a wrap for today's chat -- I gotta get back to absorbing the O Developer Preview :-)
|
Mark M. |
have a pleasant day!
|
Albert |
ok. thanks. that's good to know. (i'm on west coast, fwiw).
|
Albert |
you too.
|
Albert | has left the room |
Mark M. | turned off guest access |