Oct 5 | 7:55 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Darryl | has entered the room |
Mark M. |
howdy, Darryl!
|
Darryl |
Good Evening!
|
Mike R. | has entered the room |
Darryl |
View paste
|
Mike R. |
Hello
|
Oct 5 | 8:00 PM |
Mark M. |
howdy, Mike R!
|
Mark M. |
Darryl: whole lotta questions there
|
Darryl |
Sorry... I'm a little hung on on my application design.
|
Mark M. |
:-)
|
Darryl |
I thought I would come to the master for help!
|
Mark M. |
yeah, well, you have a complicated scenario
|
Darryl |
And BTW, the data collection from bluetooth is
client driven. I understand the pitfalls of leaving something running
in the background.
|
Mark M. |
if the activity is on-screen, is the expectation that the service will also be running?
|
Darryl |
Yes, I would think so.
|
Mark M. |
then I'd go the route of keeping the database connection in the service
|
Mark M. |
use the local binding pattern to allow the activity to ask the service for a Cursor representing whatever is needed
|
Mark M. |
allows you to keep a single database connection and not have to worry about any sort of contention
|
Mark M. |
whether you use AIDL or just the pure local binding pattern is up to you -- AIDL does not imply a remote service
|
Mark M. |
though it tends to be used for that
|
Darryl |
So then I would be showing an array list on the activity?
|
Mark M. |
no
|
Mark M. |
you'd be showing a Cursor
|
Mark M. |
that you got from the service
|
Mark M. |
when the service updates the database, you have your choice for who calls requery() on the Cursor and when
|
Oct 5 | 8:05 PM |
Darryl |
This is where I'm getting hung up. How can the service return, well, anything to the activity if they are separate?
|
Mark M. |
via the local binding pattern
|
Mark M. |
bindService()
|
Mark M. |
gives access to an API exposed by the service
|
Mark M. |
for async pushes, service -> activity, you can use a callback/listener object, or a broadcast, or createPendingResult()
|
Mark M. |
or, in this case, the service could call requery()
on the Cursor itself, if the service can arrange to do that on the main
application thread
|
Darryl |
Can the service and the activity be hitting the
database at the same time? I.e., suppose some data comes in, and I tell
my activity to update the list, and it starts to update but then more
data comes in. So then I would have the service and the activity
hitting the DB. Is that OK?
|
Mark M. |
if you are using more than one connection, there could be issues
|
Mark M. |
that is why I was recommending a single connection, held by the service
|
Mark M. |
the activity asks the service, "yo, dawg, I wants a Cursor, yo"
|
Mark M. |
the service does the query and hands back the Cursor
|
Mark M. |
you could go the route of a ContentProvider for this, if you prefer
|
Mark M. |
have the service and the activity both work off of the ContentProvider, which mediates the database
|
Darryl |
Ah, more complexity...
|
Mark M. |
yes, well, your scenario isn't precisely simple... :-)
|
Oct 5 | 8:10 PM |
Darryl |
When you mentioned about the service exposing an
API, does that mean the activity can just call public methods defined in
the service, or do I define specific methods in some way that get
exposed via binding?
|
Mark M. |
you create a Binder object, either just in Java code or via AIDL
|
Mark M. |
the activity uses the Binder as the API
|
Darryl |
And yeah, on the serface this seems simple until
you break it down. OF course, getting the client to understand that is
another matter.
|
Darryl |
Ah, OK.
|
Mark M. |
this is covered in the service chapters of _The
Busy Coder's Guide to Android Development_ and _The Busy Coder's Guide
to Advanced Android Development_
|
Darryl |
I will relook at those. In chatting here, it almost seems as though the ContentProvider may be the way to go.
|
Mark M. |
it has its advantages
|
Mark M. |
warning, though -- they're public by default
|
Mark M. |
add android:exported="false" to limit access to your own process
|
Mark M. |
(add that to the <provider> element in the manifest)
|
Darryl |
Thanks for the warning!
|
Mark M. |
let's swing over to Mike -- Mike, do you have a question?
|
Darryl |
And also, thanks for your good books.
|
Mike R. |
Back to diagnosing stack traces.
|
Mike R. |
seems i'm getting a problem in this method:
|
Mike R. |
View paste
|
Mike R. |
getting a null exception in the last catch
|
Mike R. |
says that println needs a message
|
Mark M. |
huh?
|
Oct 5 | 8:15 PM |
Mark M. |
could you paste the stack trace, here or in a github gist or something?
|
Mike R. |
sure thing
|
Mike R. |
View paste
(6 more lines)
|
Mark M. |
e.getLocalizedMessage() is returning null for some other exception
|
Mark M. |
any particular reason you're using that, rather than just passing e?
|
Mike R. |
not really
|
Mark M. |
rather, passing e as the third parameter, and passing some other useful string as the 2nd?
|
Mike R. |
could do that also
|
Mark M. |
tough to tell what the actual crash is, at least from this trace
|
Mike R. |
i just assumed that a system-generated exception would include a localized description
|
Mark M. |
nice thought
|
Mike R. |
as far as the actual crash, i think is has to do with one of my serialized objects
|
Mark M. |
:: insert obligatory reference to "never assume" joke here ::
|
Mike R. |
very nice
|
Mark M. |
yeah, my guess is that you're blowing up in one of your serialization methods, but no good way from this trace to tell which
|
Mike R. |
in looking at my code, one of the objects that I'm
serializing could possilby have a reference to another object that's
set to null
|
Mike R. |
I'm guessing that's a no-no when it's time to serialize?
|
Mark M. |
I haven't played with Java serialization in years and years
|
Mike R. |
well, that's my guess anyway.
|
Mark M. |
hence, I forget the rules
|
Oct 5 | 8:20 PM |
Mike R. |
i can pretty easily put a fix to make sure that reference is never null.
|
Mark M. |
probably not a bad idea
|
Mike R. |
but i'd rather not have to do this through trial and error
|
Mike R. |
unless I have to :)
|
Mark M. |
well, write a test case
|
Mike R. |
ok. that sounds like a good idea. thanks.
|
Mike R. |
that's it for me.
|
Mark M. |
ok
|
Mark M. |
Darryl: got another question?
|
Mike R. | has left the room |
Darryl |
No, not really.
|
Mark M. |
ok
|
Darryl |
If there is no one else, I was wondering one thing though.
|
Darryl |
Since you're pretty heavy into the Android
community, why did they make the activities completely destroy
themselves when rotating? IT seems to hang up a lot of people.
|
Darryl |
Myself included. :)
|
Mark M. |
in part, to make absolutely certain you get the right resources (e.g., landscape layouts)
|
Mark M. |
happens for all configuration changes, not just rotation (e.g., insert/remove from dock, change locale in Settings)
|
Oct 5 | 8:25 PM |
Darryl |
It just seems, well, unnecessarily destructive. I'm not saying other ways are better, just trying to understand why.
|
Darryl |
Thanks again for your help.
|
Darryl | has left the room |
Oct 5 | 8:55 PM |
Mark M. | turned off guest access |