Nov 5 | 3:50 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Nov 5 | 3:55 PM |
Guy | has entered the room |
Mark M. |
hello, Guy
|
Mark M. |
how can I help you today?
|
Guy |
Hi
|
Guy |
a listview with an imageview and textviews. what is the best way to do it with a simplecursoradapter and viewbind or arrayadapter and viewholder
|
Mark M. |
if your data is in the form of a Cursor, use a CursorAdapter
|
Nov 5 | 4:00 PM |
Mark M. |
if your data is in the form of an ArrayList, use an ArrayAdapter
|
Guy |
its from sqlite db so I guess thats a CursorAdapter?
|
Mark M. |
I would certainly start there
|
Bob R. | has entered the room |
Bob R. |
Hi Mark
|
Mark M. |
it is possible that you will have other reasons why you need to convert the data from a Cursor to an ArrayList
|
Mark M. |
but, until you have a need for that, stick with the Cursor and CursorAdapter
|
Guy |
OK thanks.
|
Mark M. |
let me take a question from Bob, and I will be back with you shortly
|
Mark M. |
Bob: hi -- do you have a question?
|
Bob R. |
Hi Mark
|
Bob R. |
Quick question
|
Bob R. |
I noticed that variables are initialized to null
|
Bob R. |
Is this a statdard?
|
Mark M. |
I would describe it as more of a personal style
|
Mark M. |
you do not see that style used much nowadays
|
Mark M. |
I am a bit "old school" in my Java :-)
|
Bob R. |
I thought that this may cause the NullPointerException type of errors I've been getting
|
Mark M. |
no, that is because you never set it to something other than null
|
Mark M. |
the data members always start null, even if you do not explicitly assign it
|
Bob R. |
I thought that it would be best to avoid null where possible. But I'm still a newbe to java
|
Nov 5 | 4:05 PM |
Mark M. |
(exception being primitive data members, which have a type-specific default initialization value, like 0 for an int)
|
Mark M. |
null means "we do not have an appropriate object back"
|
Mark M. |
er, "we do not have an appropriate object *yet*"
|
VineelAryan8125 | has entered the room |
Bob R. |
OK. I have my app where the internal file is saved but later the file cant be opened
|
Bob R. |
I thought that I may have null chars in the file
|
VineelAryan8125 | has left the room |
VineelAryan8125 | has entered the room |
Mark M. |
that is unlikely to be the source of a NullPointerException
|
VineelAryan8125 |
Hello Mark
|
Mark M. |
moreover, if you read your stack trace, you will know what line is causing the NullPointerException
|
Bob R. |
OK, any suggestions as to where I cal look
|
Mark M. |
I would recommend reading the chapter on debugging in your Java book
|
Mark M. |
(Vineel: hello! I will be with you shortly!)
|
Bob R. |
How about on an andeoid phone?
|
Mark M. |
I do not understand that question, sorry
|
Bob R. |
OK I;kk read it again
|
Mark M. |
Bob: let me take questions from the others, and I will be back with you shortly
|
Mark M. |
VineelAryan8125: do you have a question?
|
Bob R. |
Checking what the error is.
|
VineelAryan8125 |
yeah
|
Bob R. |
OK thanks for your time.
|
VineelAryan8125 |
is there a way to implement the navigation drawer in multipane?
|
Mark M. |
what is "multipane"?
|
VineelAryan8125 |
in tablets
|
Nov 5 | 4:10 PM |
Mark M. |
you can certainly have a navigation drawer as part of a master-detail or similar "multipane" activity
|
VineelAryan8125 |
i've searched for it but ended up with some bad examples. Do you know of any good examples out there?
|
Mark M. |
it would be no different than any other use of a navigation drawer, so I fail to understand what your concern is
|
Mark M. |
the navigation drawer does not care how many inches of screen size you have, or what classes are organizing the widgets
|
Mark M. |
what specifically are you worried about?
|
VineelAryan8125 |
im
|
Bob R. | has left the room |
Mark M. |
VineelAryan8125: let me take a question from Guy, and we can follow up on this shortly
|
Mark M. |
Guy: do you have another question?
|
VineelAryan8125 |
i mean, on the tablets, the navigation drawer shouldn't be there, but with the master-detail fragment
|
VineelAryan8125 |
ok
|
Nov 5 | 4:15 PM |
Guy |
CursorAdapter do you have some example code?
|
Mark M. |
the book covers CursorAdapter
|
Mark M. |
I use it in several places
|
Guy |
thank you
|
Mark M. |
VineelAryan8125: OK, back to you
|
Mark M. |
the "master" in "master-detail" represents some collection of content
|
Mark M. |
the navigation drawer could let you get to other such collections of content
|
Mark M. |
or to other major landing points within the application (e.g., the shopping cart in an e-commerce app)
|
VineelAryan8125 |
on the phones, the navigation drawer is usually the master right?
|
Mark M. |
no
|
Mark M. |
the navigation drawer is never the master
|
VineelAryan8125 |
ok
|
Mark M. |
in the Gmail app, for example, the "master" would be a list of conversations, and the "detail" would be the messages in a conversation
|
Mark M. |
the navigation drawer lets you get to different accounts, different labels, etc.
|
Nov 5 | 4:20 PM |
VineelAryan8125 |
oh i get it
|
Mark M. |
let me go back to Guy for a bit, and I can take another question from you shortly
|
Mark M. |
Guy: do you have another question?
|
VineelAryan8125 |
sure
|
Guy |
thanks. :-) I could recycle the CursorAdapter with a spinner.
|
Mark M. |
sorry, but I do not understand the "recycle" part of that comment
|
Mark M. |
you can put a CursorAdapter in a Spinner, though
|
Guy |
yes
|
Guy |
OK thanks :-)
|
Nov 5 | 4:25 PM |
Mark M. |
VineelAryan8125: do you have another question?
|
VineelAryan8125 |
i'm trying to load images using the dropbox sdk. The images are loading fine, but sometimes, the asynctask throws a thread pool exceeded exception. So, i've copied the asynctask from the android source and modified the thread pool to 9999. Will that do good or will it create any performance issues or any other problems?
|
Mark M. |
that is not a great solution, as too many threads can cause too much overhead from task switching
|
Richard L. | has entered the room |
Mark M. |
I would leave the thread pool where it is (or have it smaller, even), but use a larger queue
|
Mark M. |
or, better yet, use a different algorithm for choosing what to load, as downloading 9999 images will be much too much bandwidth
|
Mark M. |
(Richard: I will be with you shortly!)
|
Richard L. |
Thank you sir.
|
VineelAryan8125 |
ok thanks
|
Mark M. |
for example, only download images when the user scrolls, using placeholders in the meantime
|
VineelAryan8125 |
i'm already using a viewholder in my listview
|
Mark M. |
that only deals with the ImageView, not the source of images
|
VineelAryan8125 |
oh sorry, place holders, ok
|
Mark M. |
Richard: do you have a question?
|
Richard L. |
Yes, I am still formulating it.
|
Richard L. |
1 minute.
|
Mark M. |
wow -- complicated question! :-)
|
Richard L. |
LOL
|
Nov 5 | 4:30 PM |
Mark M. |
while Richard is formulating, if anyone else has a question, chime in
|
Richard L. |
View paste
|
Mark M. |
how frequently are you trying to update this data?
|
Richard L. |
every second. I currently use a handler for my notification and an alarm service for my widget.
|
Mark M. |
why are you treating your Notification-update logic differently than your app widget-update logic?
|
Nov 5 | 4:35 PM |
Richard L. |
I use an alarm service for my widget because I have read that when updating widgets very frequently, your best bet is to use an alarm service. This way, it will not keep the device awake when it is asleep.
|
Mark M. |
that is only when contrasted with android:updatePeriodMillis, which, under the covers, uses a _WAKEUP alarm
|
Richard L. |
yes, but android:updatePeriodMillis will run a max of once every 30 minutes, correct?
|
Mark M. |
correct
|
Mark M. |
my point is that what you read is immaterial for your use case
|
Richard L. |
I am sorry, what do you mean by that?
|
Mark M. |
never mind
|
Mark M. |
first, let me state for the record that I hate apps like this with the fiery passion of a thousand suns
|
Mark M. |
as it's a constant battery drain, doing IPC every second
|
Mark M. |
that being said
|
Mark M. |
you have two choices: evil and another form of evil
|
Richard L. |
Mark, my app does not affect my battery life at all. Not even 1% shows up in the battery use. But I hear you.
|
Mark M. |
one option is to go with zero services, having AlarmManager invoking a BroadcastReceiver every second and doing the calculations and app widget + Notification updates
|
Nov 5 | 4:40 PM |
Richard L. |
WOAH. That is snazy.
|
Mark M. |
the other option is to go with one everlasting service, using something (I'd go ScheduledExecutorService instead of Handler, personally to trigger the every-second calculations and app widget + Notification updates
|
Mark M. |
both are anti-patterns, in that AlarmManager is not designed for that frequent of work, and that services are not designed to be everlasting
|
Mark M. |
in terms of CPU load, the everlasting service would be the better option
|
Mark M. |
RAM impact is roughly equivalent
|
Mark M. |
(i.e., both should consume about the same heap space, and hence system RAM)
|
Mark M. |
and the everlasting service probably makes coding a bit esier
|
Mark M. |
er, easier
|
Mark M. |
so, if somebody pointed a gun at my head to try to force me to write this app, I'd lean in that direction
|
Mark M. |
regardless, *please* let the user configure the polling period
|
Richard L. |
LOL
|
Richard L. |
Mark, I run my app all the time on my device, and I am telling you the battery life hit is barley anything.
|
Richard L. |
My calculations that run are very minimal.
|
Mark M. |
the effect will be worse on older/slower devices, I imagine
|
Mark M. |
moreover, the "battery blame screen" would not necessarily blame your app
|
Mark M. |
the calculations are dwarfed by the IPC calls, I would guess
|
Richard L. |
Good point.
|
Nov 5 | 4:45 PM |
Mark M. |
anyway, that's my recommendation
|
Mark M. |
Guy: do you have another question?
|
Richard L. |
Because I am currently using a handler for my notification updates, does that still run when the phone is asleeep?
|
Richard L. |
oh sorry, I will wait.
|
Mark M. |
Vineel: do you have another question?
|
VineelAryan8125 |
yes
|
VineelAryan8125 |
In some apps there is a toggle button to toggle between list and grid type. What is the technique behind that? Are they really toggling between listview and gridview or is it gridview changing the numColumns programmatically?
|
VineelAryan8125 |
or neither?
|
Mark M. |
off the top of my head, I would assume that they are toggling between ListView and GridView, but I have not investigated it
|
Mark M. |
you can use uiautomatorviewer to find out, for a specific app, what they are doing
|
Mark M. |
if you only see a GridView, then they are changing the # of columns
|
Mark M. |
if you see a GridView and a ListView, with one having visibility of GONE, they are toggling between the two, most likely
|
VineelAryan8125 |
can i use uiauomatorviewer on phone?
|
Mark M. |
yes
|
Mark M. |
very very handy for deciphering how a production app does its UI
|
VineelAryan8125 |
ok
|
VineelAryan8125 |
thanks mark
|
Mark M. |
Richard: back to you
|
Mark M. |
Handler does not keep the device awake
|
VineelAryan8125 |
that's it for now. thanks for your answers. See you later
|
Nov 5 | 4:50 PM |
VineelAryan8125 | has left the room |
Mark M. |
neither will ScheduledExecutorService
|
Richard L. |
Thank you Mark.
|
Mark M. |
and neither will AlarmManager, if you are not using a _WAKEUP alarm
|
Mark M. |
if anyone has any questions, chime ni
|
Mark M. |
er, chime in
|
Richard L. |
Since I am using one service, as per your recommendation, it is possible to get my widget to update without having a specific service dedicated for updating my widget?
|
Mark M. |
yes
|
Mark M. |
just use AppWidgetManager and updateAppWidget()
|
Mark M. |
just as you use NotificationManager and notify()
|
Richard L. |
And updateAppWidget() can be called more than once every 30 mins?
|
Guy |
Thanks Mark. I was reading about the CursorAdapter
|
Mark M. |
Richard: the only tricky part is knowing your app widget ID(s), which you can cache (in the service or as a static data member) and keep persistently in case you get kicked out of RAM
|
Richard L. |
So I would have a total of two services then, assuming a user has added a widget?
|
Mark M. |
no, just one
|
Mark M. |
your same service would update the Notification and the app widget based upon your every-second poll
|
Nov 5 | 4:55 PM |
Richard L. |
Got it, sorry, I misread.
|
Richard L. |
I am all set Mark. Thank you very much for offering this service, pun intended. Have a good day.
|
Mark M. |
happy to be useful!
|
Guy |
Have a nice day :-)
|
Guy | has left the room |
Nov 5 | 5:00 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to http://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Thursday at 10am Eastern
|
Mark M. |
have a pleasant day!
|
Richard L. |
sweet, I was copy and pasting!
|
Richard L. | has left the room |
Mark M. | turned off guest access |