Mark M. | has entered the room |
Sep 23 | 7:55 PM |
Mark M. | turned on guest access |
Sep 23 | 8:00 PM |
spargonaut | has entered the room |
spargonaut |
hey there
|
Mark M. |
howdy, spargonaut!
|
spargonaut |
great books btw. i've been devouring them
|
Mark M. |
thanks! I find them to be best served with salsa!
|
Mark M. |
:-)
|
spargonaut |
nice
|
Mark M. |
how can I help you today?
|
Mike R. | has entered the room |
spargonaut |
well, i've got a couple of questions actually
|
spargonaut |
the first is...
|
Mike R. |
Hello
|
spargonaut |
i'm wanting to pass some custom objects from one activity to the next
|
Mark M. |
urk
|
Mark M. | |
spargonaut |
but I can't seem to figure out an easy / logical way to do that
|
Mark M. |
(btw, hi, Mike!)
|
Mark M. |
what is the nature of the "custom objects"?
|
spargonaut |
hey mike!
|
spargonaut |
thanks mark, i'll look this over and see if it explains what i'm looking for
|
Mark M. |
uh, well, it's more that it explains why your question makes me nervous
|
Sep 23 | 8:05 PM |
spargonaut |
oh. heh
|
spargonaut |
well, let me explain my app a little
|
spargonaut |
the main activity make a request to an LBS and gets back an xml doc
|
spargonaut |
i parse the xml doc into a custom object and put it into a hashmap
|
spargonaut |
since i'm relying on an http reply, i've put the request into an extended async class
|
spargonaut |
when it says its built all of the entries of the
hashmap, i'm wanting a button that starts a listactivity of all the
items in the hashmap
|
spargonaut |
but i can't figure out how elegantly pass the hashmap from one activity to the next
|
Mark M. |
to me, it feels like you are putting too many roles in the first activity
|
spargonaut |
hrmm...
|
Mark M. |
off the cuff, here's how I'd consider approaching it:
|
Sep 23 | 8:10 PM |
Mark M. |
have the LBS HTTP call, parsing, and resulting data be handled by something other than an activity
|
Mark M. |
most likely a Service
|
spargonaut |
k
|
Mark M. |
have the first activity tell the service, "yo, go generate the results and let me know when you're done"
|
spargonaut |
k
|
Mark M. |
service does the work and lets the activity know
by any number of possible means (callback/listener object, "narrowcast"
broadcast Intent, createPendingResult(), etc.)
|
Mark M. |
first activity then starts up second activity
|
Mark M. |
second activity tells the service, "yo, give me the data"
|
spargonaut |
ahh. alright
|
Mark M. |
service returns the data, probably via an API exposed via onBind()
|
Mark M. |
basically, you keep your model and your GUI separate
|
spargonaut |
so i guess the service is sort of like a background thread
|
Mark M. |
the service would use your existing AsyncTask, with minor mods probably
|
spargonaut |
werd
|
Mark J. | has entered the room |
Mark M. |
there are other possible patterns here that some
people use (e.g., custom Application object or static data member for
holding the model data)
|
spargonaut |
sweet. you've definitely given me stuff to chew on.
|
Mark M. |
IMHO, any of those are better than trying to keep passing your model data around in Intent extras
|
Mark M. |
OK, let me give the others a shot, and we'll swing back to you later for follow-up or additional questions
|
spargonaut |
yea, i saw a bunch of those suggestions, but none of them seemed quite right
|
Mark M. |
(btw, hi, Mark J!)
|
Mark M. |
Mike: got a question?
|
Mark J. |
Heya
|
spargonaut |
yea, werd
|
Mike R. |
sure do.
|
spargonaut |
thx
|
Mike R. |
last time we went over some stack traces i was getting
|
Mark M. |
yup
|
Mike R. |
specifically, crashing after a call to onActivityResult
|
Sep 23 | 8:15 PM |
Mark M. |
yup, and I theorized it might be tied to a rotation or something
|
Mike R. |
you had guessed that there was a configuration change going on and some variables were not initialized
|
Mike R. |
turns out you were right.
|
Mark M. |
booya!
|
Mike R. |
configuration changes / onActivityResult
|
Mark M. |
well, ok, it sucks for your code
|
Mike R. |
it seems to be an activity lifecycle problem
|
Mike R. |
onCreate is definitely being called.
|
Mike R. |
problem is that for most of my activities, the last line of onCreate is a bindService call
|
Mike R. |
so what's happening is onCreate is called, then
onActivityResult is called and then my onService method is called - in
that order
|
Mark M. |
by "my onService method", you mean onServiceConnected() in the ServiceConnection?
|
Mike R. |
exactly
|
Mark M. |
and the data member in question isn't being initialized until onServiceConnected()?
|
Mike R. |
in most cases, onActivityResults sets some variables and re-builds the view.
|
Mike R. |
correct again
|
Mike R. |
so, i just test to see if my point to the service
is null and if it is I set my variables and let onServiceConnected
handle building the view.
|
Mark M. |
seems reasonable
|
Mike R. |
problem is, i have some onActivityResult methods that do a lot more complicated processing.
|
Mark M. |
that's why mankind invented the [Delete] key
|
Mark M. |
:-)
|
Sep 23 | 8:20 PM |
Mike R. |
so i've set a bunch of booleans and let onServiceConnected test the booleans and do that processing there if necessary
|
Mike R. |
it works (i think), but it seems kind of a kludge
|
Mike R. |
is there a more elegant, maintainable way to handle this activity lifecycle issue?
|
Mark M. |
well, I don't know any way you can force onActivityResult() to occur after onServiceConnected()
|
Mark M. |
I haven't tried passing a ServiceConnection
between activities via onRetainNonConfigurationInstance(), so I don't
know if that causes memory leaks
|
Mike R. |
i've thought of trying that, but it scares me
|
Mike R. |
is there a way to force bindService to be more synchronous?
|
Mark M. |
a slightly simpler kludge might be to have
onActivityResult() see if the connection is ready, and if not, use
post() (on View or Handler) to delay execution of its work
|
Mark M. |
no, bindService is very asynchronous
|
Mike R. |
never used post(). where is it documented?
|
Mark M. |
it's a method on View and on Handler
|
Mark M. |
it takes a Runnable and sticks it on the queue that the main application thread works off of
|
Mark M. |
actually, now that I think about it, that's probably not going to help
|
Mike R. |
i'll take a look at it, but i may just stick to my booleans
|
Mark M. |
yeah, that's probably your best short-term bet
|
Mike R. |
thanks mark
|
Sep 23 | 8:25 PM |
Mark M. |
I do need to figure out if we can get a ServiceConnection to survive a configuration change, though
|
Mark M. |
that strikes me as an important bit of info
|
Mark M. |
I'll make a point to try to get an answer on that
|
Mike R. |
yeah. let me know what you find out. i'll do some experimenting as well
|
Mark M. |
Mark J: got a question?
|
Mark J. |
View paste
|
Mark J. |
oopsie
|
Mark M. |
um, could you explain a bit more about what you mean by that "structure in a database"?
|
Mark J. |
Well, what I meant, Is it possible to store things
multiple directories deep? Like the standard tree filesystem of most
common filessystems
|
spargonaut |
alright fellas, i'm outta here. thanks fore the
help mark, i'll chat with you next time. good luck with your problems
mike and other mark.
|
spargonaut | has left the room |
Mark M. |
typical way to do that in a relational database is
to have a table that has a foreign key relationship back to itself, to
identify the parent
|
Mark M. |
for example, CREATE TABLE stuff (_ID INTEGER PRIMARY KEY AUTOINCREMENT, categoryName TEXT, parentId INTEGER)
|
Mark M. |
parentId would be NULL for roots (e.g., Category1)
|
Mark J. |
Because I started playing around in a client, and
was having trouble breaking up the content, because I could not separate
the content into sub categories very easily
|
Mark M. |
a bit more common nowadays is to use a tagging system, but that does not usually enforce any sort of hierarchy
|
Sep 23 | 8:30 PM |
Mark J. |
Right, so what my wonder was, is it possible to
structure something like system folders, breaking things up into
directories 5+ levels deep?
|
Mark M. |
sure
|
Mark M. |
use the structure I just described
|
Mark M. |
level5's parentId is level4
|
Mark M. |
level4's parentId is level3
|
Mark M. |
etc.
|
Mark J. |
Alrighty
|
Mark M. |
certain types of queries are rather painful this
way, which I suspect is one of the reasons people tend to try something a
bit more flat, like tags
|
Mark J. |
Okay
|
Mark J. |
My other question
|
Mark M. |
um, hang on
|
Mark J. |
What would the process be to build a database before hand, and then import it into a project?
|
Mark J. |
alright
|
Mark M. |
Mike: did you have a 2nd question?
|
Mike R. |
no i'm good
|
Mark M. |
(Mark -- just trying to be fair to all participants)
|
Mark M. |
OK, back to Mark
|
Mark J. |
Oh yeah, understandable
|
Mark M. |
the process depends a bit on the size of the database
|
Mark M. |
there are plenty of SQLite tools you can use from your desktop or browser to create a database
|
Sep 23 | 8:35 PM |
Mark M. |
I use SQLite Manager, an extension in Firefox
|
Mark J. |
Right, and that is the route I am taking
|
Mark M. |
but there are others
|
Mark M. |
then, I'd put it either in assets/ or res/raw/ of the project
|
Mark M. |
on first run, if you do not see your database
there, copy it from the APK to the database directory using Java I/O,
operating on the InputStream you get from the asset or raw resource
|
Mark M. |
there's a size limit where this strategy fails (1MB, I think)
|
Mark J. |
Aww really?
|
Mark M. |
bigger than that, you need to cheat slightly and give your database some file extension that Android won't try compressing
|
Mark M. |
.png or .mp3 might work
|
Mark J. |
Okay, well once I have my database imported, how can I query it?
|
Mark M. |
normally
|
Mark M. |
using SQLiteDatabase
|
Mark M. |
once it is in the regular filesystem, you use it like any "normal" SQLite database
|
Mark M. |
SQLiteOpenHelper may or may not be terribly useful
|
Mark M. |
haven't tried it in this scenario
|
Mark J. |
Okay
|
Mark M. |
also, bear in mind you'll be taking up extra
on-board flash space -- some for the copy in the APK, some for the copy
on the filesystem
|
Mark M. |
depending on the database size, this may not make you very popular
|
Mark J. |
:D
|
Sep 23 | 8:40 PM |
Mark M. |
BTW, before I forget, if either of you are Eclipse
users, grab the new ADT plugin (0.9.9) if you are using the 0.9.8
version released earlier this month
|
Mark M. |
apparently, the new version fixes some fairly significant bugs
|
Mike R. | has left the room |
Mark M. |
well, obviously Mike ran off to check his copy of Eclipse... :-)
|
Mark M. |
any other questions?
|
Mark J. |
Umm, not at the moment
|
Mark J. |
Just grabbed the firefox plugin for SQLite :)
|
Sep 23 | 8:45 PM |
Mark J. |
Any good books or resources to look at for SQLite basics?
|
Mark M. |
I have The Definitive Guide to SQLite (published by Apress)
|
Mark M. |
at the time, at least, it was the only book out there
|
Mark M. |
not bad, but it is best only for general SQLite stuff
|
Mark M. |
it has nothing on Android's SQLite integration
|
Mark M. |
the docs on sqlite.org usually cover most of my needs -- I haven't cracked that book open in a year or so
|
Mark J. |
Alrighty
|
Sep 23 | 8:50 PM |
Mark J. |
Sweet, I just found some tutorials from GoogleTechTalks :)
|
Sep 23 | 8:55 PM |
Mark M. |
OK, any final questions?
|
Mark J. |
No, But I will see you next time
|
Mark M. |
yup, got two more scheduled for next ewek
|
Mark M. |
er, week
|
Mark M. |
ok, well, have a pleasant weekend!
|
Mark J. |
Same to you
|
Mark J. | has left the room |
Mark M. | turned off guest access |