Mark M. | has entered the room |
Jul 11 | 7:25 PM |
Mark M. | turned on guest access |
jdub | has entered the room |
Mark M. |
hello, jdub!
|
Mark M. |
how can I help you today?
|
jdub |
Hi Mark
|
jdub |
Well I am still having troubles with Horizontal List View
|
jdub |
I looked at your example.
|
tunneling | has entered the room |
jdub |
I followed it, but nothing shows up when I use HorizontalListView
|
tunneling |
How D
|
jdub |
So I have a question
|
Mark M. |
(hello, tunneling -- I will be with you shortly!)
|
jdub |
The HorizontalListView also need to add children to its view
|
jdub |
It does so through a setAdapter call normally
|
Jul 11 | 7:30 PM |
jdub |
so I somehow would have to perform to setAdapter calls, one for the ListView and one for the HorizontalListView
|
Mark M. |
correct
|
EGHDK | has entered the room |
Mark M. |
the setAdapter() calls for the HorizontalListView
would presumably be done in getView() of the adapter that you are using
for the ListView
|
Yurii L. | has entered the room |
jdub |
Where should that second setAdapter call happen, in the getView
|
Mark M. |
(hello, EGHDK -- be with you in a bit!)
|
jdub |
Yeah I tried that but I get an empty list
|
Mark M. |
(hello, Yurii -- you're in line after tunneling and EGHDK!)
|
jdub |
arg
|
jdub |
:-)
|
jdub |
It looks like everything is getting called but nothing shows up.
|
tunneling |
i don't have any questions
|
jdub |
Any thoughts?
|
Mark M. |
jdub: not really
|
Mark M. |
first, adapters-in-adapters is not common
|
jdub |
Yeah, maybe I need to look at the Android source code
|
jdub |
Yeah I noticed that on the internet
|
Mark M. |
possibly, though since HorizontalListView is not part of Android, I'm skeptical that it will help
|
Mark M. |
if somebody pointed a gun to my head and forced me
to try to implement what you're trying, I'd start with my RateList
sample, and replace the RatingBar with the HorizontalListView
|
jdub |
Oh well. I've fropped about a week of time on this. I think it may be time to throw in the towel.
|
Mark M. |
I'd call setAdapter() on the HLV in getView() of the ListView adapter, much like how I populate the RatingBar in the sample
|
jdub |
Yeah. I thought I had done that but...
|
Mark M. |
and then I'd pray to the deity of my choice and hope for a miracle
|
Mark M. |
:-)
|
jdub |
hahah LOL!
|
jdub |
Ok well if I solve this, I'll let you know how.
|
Mark M. |
it's the sort of thing that in principle should work, but I can see lots of potential "gotchas"
|
Jul 11 | 7:35 PM |
jdub |
indeed
|
Mark M. |
if you haven't done so already, post what you can to StackOverflow, and hope that somebody else has gone down this path already
|
jdub |
I think the gotcha's have beat me down
|
Mark M. |
meanwhile...
|
Mark M. |
tunneling: if you come up with a question later on, let me know
|
jdub |
Ok Thanks. I'll let you know
|
Mark M. |
EGHDK: do you have a question?
|
tunneling |
k
|
EGHDK |
Yeah, I'm trying to do the sample AlertDialog on the d.android site, and it keeps crashing on me.
|
Mark M. |
what sample are you referring to?
|
EGHDK |
I'm doing it in an onClick method. I'll post the sample.
|
EGHDK |
View paste
|
Mark M. |
and what's your stack trace?
|
EGHDK |
So I take that code, and I put it in my own method.
|
EGHDK |
I added builder.show(); to the end of it and removed the return statement.
|
EGHDK | |
Mark M. |
just do show()
|
EGHDK |
Okay, running it now. I'll let you know if it works.
|
Mark M. |
I'll swing back to you in a bit to find out
|
Mark M. |
meanwhile...
|
EGHDK |
yep
|
Mark M. |
Yurii: do you have a question?
|
Jul 11 | 7:40 PM |
Yurii L. |
sure, I've seen you were discussing
HorizontalListView, I don't want implement it all my self. what is the
best available lib in your opinion?
|
Mark M. |
I'm only aware of one HorizontalListView: https://github.com/MeetMe/Android-HorizontalLis...
|
jdub |
Concur
|
Mark M. |
but, then again, I've never wanted to use one, so I haven't exactly searched high and low for them
|
EGHDK |
Nope. builder.show() line shows up as the error.
|
Mark M. |
EGHDK: what's your stack trace?
|
Yurii L. |
you should not call show on builder, get dialog from builder.create() and call show on that dialog
|
Mark M. |
actually, you shouldn't do either of those things, but rather use a DialogFragment, but that's a whole 'nuther story
|
Mark M. |
I was focusing on trying to get past whatever configuration issue there might be with the dialog
|
Mark M. |
which is why a stack trace would be awfully handy :-)
|
tunneling |
lol
|
EGHDK |
View paste
(14 more lines)
|
Mark M. |
after your cut-and-paste work, what did you wind up with as your AlertDialog.Builder constructor call?
|
Jul 11 | 7:45 PM |
EGHDK |
My code
|
EGHDK |
View paste
(14 more lines)
|
Mark M. |
bzzzt
|
Mark M. |
never use getApplicationContext() unless you know SPECIFICALLY WHY you are using getApplicationContext()
|
Mark M. |
and, in general, never use getApplicationContext() for GUI-related operations
|
EGHDK |
Oh goodness.
|
Mark M. |
here's the best blog post on this subject I have ever seen: http://www.doubleencore.com/2013/06/context/
|
Mark M. |
basically, all Contexts are not created equal
|
EGHDK |
Is it bad that I have read that... but I still don't full comprehend context?
|
Mark M. |
yeah, well, Context isn't one of Android's better design decisions, IMHO
|
EGHDK |
So what's the general rules on Contexts?
|
Mark M. |
click that link, scroll down to Context Capabilities, and look at the table
|
tunneling |
hey, i have a question now
|
Mark M. |
personally, my basic rule is what I stated earlier: only use getApplicationContext() when you know *why*
|
Mark M. |
(tunneling: be with you shortly!)
|
Mark M. |
for example, if you need to create a singleton
that in turn needs a Context, the Application is the best answer, as it
does not leak memory
|
Mark M. |
(at least, not intrinsically)
|
EGHDK |
so when I do getApplicationContext inside of an application for a dialog... there is no context?
|
Mark M. |
it's more that there's no GUI
|
Mark M. |
Application is not tied to the UI framework the way an Activity is
|
EGHDK |
I'm just trying to understand the table.
|
Mark M. |
and since an Activity is a Context, use `this` instead of `getApplicationContext()`
|
Mark M. |
(and I *so* wish this chat supported Markdown syntax...)
|
EGHDK |
Activity extends context?
|
Mark M. |
sure
|
Jul 11 | 7:50 PM |
EGHDK |
So I purely throw in "this" for where I need context in my case right now?
|
Mark M. |
the first 3 columns represent classes that inherit from Context
|
Mark M. |
correct
|
Mark M. |
(since I presume that `this` is an Activity)
|
Mark M. |
let me give the others a shot, and I'll be back with you later
|
EGHDK |
yep
|
Mark M. |
tunneling: you indicated that you have a question
|
EGHDK |
Oh god. "this" worked. Is there anything in logcat thats a tipoff to doublecheck context?
|
Mark M. |
you mean besides cryptic stack traces? :-)
|
tunneling |
yes
|
Mark M. |
IOW, not really
|
Mark M. |
tunneling: go ahead
|
EGHDK |
"IOW"?
|
Mark M. |
IOW = in other words
|
EGHDK |
Thanks.
|
EGHDK |
Big help.
|
EGHDK |
I'm going to reread that article
|
tunneling |
speaking of Context... I am working on an app
where I have to access a sqlite db. is it best to instansiate my helper
class in the an Application class?
|
Mark M. |
um
|
tunneling |
a bit more..
|
tunneling |
essentially i have activities getting data from
the db, and a service running in teh background that will obtain async
data from a server
|
Mark M. |
if you are going to use the database across multiple threads, you want some sort of singleton
|
Jul 11 | 7:55 PM |
tunneling |
ok, so should "singletons" be brought to life in the Application class?
|
Mark M. |
personally, I'd make the singleton be a static
data member, but use Application as the Context for the SQLiteOpenHelper
constructor
|
tunneling |
I can't see how they survive otherwise
|
Mark M. |
Application and static data members have the exact same lifespan = the life of the process
|
Mark M. |
there's no particular advantage for extending Application and putting stuff there IMHO
|
Mark M. |
and there's a definite cost, in that you can only
have *one* Application, whereas you can have as many static data members
as you need
|
EGHDK |
"but use Application as the Context" you mean "getApplicationContext()" right?
|
Mark M. |
yes, getApplicationContext() returns an instance of Application (or your designated subclass thereof)
|
tunneling |
oh.. i've never tried that. so if I first call my db helper singleton from an activity, that instance will not be GC'd?
|
Mark M. |
objects held in static data members are not garbage collected
|
tunneling |
awesome.. didn't know that!
|
Mark M. |
if you null out the static data member, *then* the
formerly-referenced object is eligible for GC, if nothing else is
holding onto it that prevents GC
|
tunneling |
ok
|
Mark M. |
static data members, Application subclasses, and running threads are the two main things that prevent GC of objects in Android
|
EGHDK |
Is there a table for what gets GC'd and what doesn't? Similar to that context table you prodivided?
|
Mark M. |
er, three main things
|
Mark M. |
EGHDK: generally speaking, that's Java, not Android
|
EGHDK |
Got it
|
EGHDK |
Can you explain what you mean by "static data member"?
|
tunneling |
i have a couple of classes that i need to be singletons. i helper for communicating with the Service and a helper for the DB.
|
Mark M. |
hmmm... the "helper for communicating with the Service" sounds fishy
|
tunneling |
sort of like IABhelper
|
Jul 11 | 8:00 PM |
Mark M. |
sorry, I have no idea what IABhelper is
|
Mark M. |
Indigenous Aborignal Bonobos helper?
|
tunneling |
why yes, yes it is.
|
jdub |
Mark u r good!
|
tunneling |
in the android samples, they have some little app for illustrating the In App Billing
|
Mark M. |
ah! in-app billing!
|
tunneling |
better than in-app bonobos
|
Mark M. |
(somewhere, a bonobo slinks off in dismay)
|
tunneling |
lol
|
jdub |
:-)
|
EGHDK |
lmao
|
tunneling |
so anyway, i was using their helper as a go-by ..
|
tunneling |
launches a thread for the network operation, then
calls the callback when it's done. i want it as a singleton because I
don't want other calls going into the service and locking me up
|
Mark M. |
um, OK, you lost me there
|
Mark M. |
and, let me take questions from the others, and I'll try to get back to you a bit later in the chat
|
Mark M. |
jdub: do you have another question?
|
tunneling |
you asked me if i had a question ;)
|
jdub |
Just one:
|
jdub |
Should I start the bottle of scotch before returning to adapter in an adapter?
|
jdub |
No I am all set
|
Mark M. |
I cannot recommend coding under the influence
|
jdub |
Hahah
|
jdub |
!
|
EGHDK |
CUI
|
EGHDK |
or CWI
|
jdub |
also goog
|
Mark M. |
Yurii: do you have another question?
|
jdub |
also good
|
Jul 11 | 8:05 PM |
Yurii L. |
sure, in application we use asynctasks for setting images on imageview in listView, backed by cursor adapter
|
Yurii L. |
when downloading file for item, set state
downloading to db, which refresh list view with progress bar against
downloading item but also blinks all the images
|
Yurii L. |
the question is when in your opinion AsyncTasks should be used
|
Yurii L. |
and when handlers
|
Mark M. |
oh, I almost never use Handler directly
|
Mark M. |
I'm either using AsyncTasks in retained fragments, or a message bus (e.g., Square's Otto)
|
Yurii L. |
do you have any good examples on otto in your book?
|
Mark M. |
not yet
|
Mark M. |
probably in Version 5.1
|
Mark M. |
I plan on adding an Event Buses chapter
|
Yurii L. |
thanks, looking forward
|
Mark M. |
covering Otto and greenrobot's EventBus, with analogies back to LocalBroadcastManager
|
Mark M. |
in the specific case of "setting images on imageview in listview", I'd use Picasso
|
Mark M. |
as it handles all the threading, recycling, etc.
|
tunneling |
have you tried volley?
|
Mark M. |
I cover Picasso in the context of using it for HTTP operations, but it works just as well for local files
|
Yurii L. |
I wanted to use it but I probably will need encryption and Picasso doesn't support one
|
Mark M. |
tunneling: no -- you can read me thoughts on Volley in the Internet chapter in the current book edition
|
Jul 11 | 8:10 PM |
Yurii L. |
I think that is what I will do. thanks
|
Mark M. |
Yurii: they might have a hook where you could plug in decryption, though I do not recall one
|
Mark M. |
EGHDK: do you have another question?
|
EGHDK |
Yeah two quick questions.
|
EGHDK |
Can you explain what you mean by "static data member"?
|
EGHDK |
When you were talking about GC.
|
jdub |
I have to bounce. Take care folks Jdub!
|
jdub | has left the room |
Mark M. |
jdub: see you later!
|
Mark M. |
EGHDK: you will also hear them referred to as static variables or class variables
|
Mark M. | |
Mark M. |
standard Java concept
|
EGHDK |
Okay cool thats what I thought, I was just making sure.
|
Mark M. | |
EGHDK |
I'm not great at java yet... sadly
|
Mark M. |
it'll grow on you
|
EGHDK |
Secon question is, I tried to do a Toast in my dialog and I tried "this" and it wouldn't compile.
|
EGHDK |
When I used "getApplicationContext" in toast... it worked.
|
Mark M. |
you may be using an anonymous inner class (e.g., new MyInterfaceName() {})
|
Mark M. |
in that case, this refers to the instance of the inner class
|
Mark M. |
use MyActivityClassName.this to get the "this" that represents the activity
|
EGHDK |
Okay, so MyACtivityClassName.this works... but what do you mean "anonymous innner class"?
|
Mark M. | |
Mark M. | |
EGHDK |
Okey Dokey
|
Jul 11 | 8:15 PM |
Mark M. |
again, another standard Java concept
|
Mark M. |
though one that IMHO gets used a bit more in Android than elsewhere
|
Mark M. |
in fact, I've been steadily removing them from my samples where practical, just to reduce confusion
|
Mark M. |
tunneling: do you have another question?
|
tunneling |
You and I talked about this connection service of
mine extensively in the past. I still haven't conquered it. So my
Service creates a Thread that creates a socket with a Remote Service.
The job of the Service is to maintain the connection, write and receive
messages. I have a library that encodes and decodes the messages from
the bits and bytes. So the Connection can receive messages from the
Remote Service and the User can send messages by clicking on a UI. I
can't seem to nail it down, but somehow the Service intermittently locks
up. Thus forcing Users to send me nasty-grams and having to FC their
apps.
|
tunneling |
So, back to my original question.. im trying to use the Helper to the Service to marshal messages.
|
Mark M. |
I can see a helper, just not the singleton part
|
tunneling |
what if I have two fragments both with UI elements that can send commands?
|
Mark M. |
I fail to see the problem
|
tunneling |
what if the User clicks an element in each fragment at the same time?
|
Mark M. |
have a queue
|
Mark M. |
commands go in the queue
|
tunneling |
i don't know how to do that!
|
tunneling |
lol
|
Mark M. |
the service pulls commands out of the queue to process them
|
Mark M. |
use a LinkedBlockingQueue
|
tunneling |
what page?
|
Mark M. |
and a thread or thread pool
|
Mark M. |
LinkedBlockingQueue is standard java, in java.util.concurrent
|
Mark M. |
I may use it in one example, hold on
|
tunneling |
ok.. take a runnable?
|
Mark M. | |
Mark M. |
I cover it in the Remote Services chapter
|
tunneling |
ok, ill check it out.
|
Jul 11 | 8:20 PM |
Mark M. |
basically, when commands come in (in this case,
via a binder), I pass them to a ThreadPoolExecutor that is backed by a
LinkedBlockingQueue
|
Jul 11 | 8:20 PM |
Mark M. |
thread(s) from the pool will process the commands as they come in
|
Mark M. |
in my case, my pool has only one thread
|
tunneling |
that's exactly what I need
|
tunneling |
I'm not creatign multiple connection threads
|
Mark M. |
give ThreadPoolExecutor and a queue a whirl
|
tunneling |
so if i can... i'm also curious if there is a technique for determining why a Thread doesn't go away.
|
Mark M. |
common Java pattern
|
Mark M. |
it doesn't go away because you haven't fallen out of your run() method
|
Mark M. |
the thread could be blocking on I/O or something
|
tunneling |
true, but doesn't it remain in the run() method if there are lingering references
|
Mark M. |
references have nothing to do with it
|
Mark M. |
once you exit run(), the thread terminates
|
Mark M. |
the *object* remains
|
Mark M. |
but the OS thread is effectively defunct
|
tunneling |
so in eclipse, when you looking at the the Thread list.. would a terminated thread remain in that list?
|
Mark M. |
ummm... I don't think so, but I haven't experimented with that precise scenario
|
Mark M. |
I don't run into thread problems all that often, and so I rarely find myself poking through the threads list in DDMS
|
Mark M. |
there's a status column IIRC
|
Jul 11 | 8:25 PM |
Mark M. |
if anyone else has any questions, chime in, as we're running out of chat time
|
EGHDK |
Since I'm having trouble with basic java concepts,
is there any "one" resource I should look into? Oracle docs... or
something else? Like if I was to spend this entire weekend to read one
source of Java, what would I read?
|
tunneling |
occasionally i need to terminate the connection
thread, and connect to a different server. i'm having trouble making the
original thread go away.
|
EGHDK |
I never really did Java development before Android.
|
Yurii L. |
what http library would you recommend to use?
|
Mark M. |
EGHDK: I learned Java back when dinosaurs roamed the Earth, so I'm not up on the latest educational resources
|
EGHDK |
bah.
|
EGHDK |
Stupid dinos
|
Mark M. |
tunneling: not sure what to tell you
|
Mark M. |
Yurii: that depends on what sort of HTTP I/O you're trying to do
|
Mark M. |
Retrofit is pretty nice for JSON
|
Mark M. |
Picasso is pretty nice for images
|
Yurii L. |
JSON
|
tunneling |
i'll just go away and sit in the corner
|
Mark M. |
tunneling: it's more that I have no good way of telling you what your problem is
|
tunneling |
yea, it's a bit vague. i think my wife could tell you my problem...lol!
|
tunneling |
she has a list.
|
Mark M. |
Yurii: Retrofit works nicely with JSON Web services
|
EGHDK |
lmao
|
EGHDK |
^
|
Mark M. |
I also just heard about https://github.com/koush/ion today, and it looks rather interesting
|
tunneling |
and they aren't in a Queue either.
|
Yurii L. |
but it is not a REST web service :(
|
tunneling |
koush also has a nice Async library.. ion uses it
|
Mark M. |
Yurii: so long as the requests are basic GET operations, Retrofit should work
|
tunneling |
it helps to look at the tests to get a good feel for it's capabilities.
|
Jul 11 | 8:30 PM |
Yurii L. |
thanks, I will look deeper into retrofit and ion
|
Mark M. |
anyway, that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to http://commonsware.com/office-hours/ shortly
|
tunneling |
that's a wrap!
|
Mark M. |
next chat is Tuesday at 4pm Eastern
|
EGHDK |
Next Tuesday
|
Mark M. |
have a pleasant day!
|
EGHDK |
I'm going to go make myself a wrap.
|
tunneling |
bigh.. thanks Mark
|
tunneling | has left the room |
EGHDK | has left the room |
Yurii L. | has left the room |
Mark M. | turned off guest access |