Office Hours — Today, May 29

Wednesday, May 27

May 29
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
Vasanthi
has entered the room
Mark M.
hello, Vasanthi
how can I help you today?
9:00 AM
Vasanthi
Hello, Mark. Thank you.
I have a few questions and would appreciate if you could answer them
Mark M.
I can try
Vasanthi
Thanks.
1. Simple_list_item_2 – how come that doesn’t have a layout as the root element?
Mark M.
hold on
OK, I am confused
If you are referring to android.R.layout.simple_list_item_two, it uses a TwoLineListItem as the root element, holding a pair of TextView widgets
er, sorry, android.R.layout.simple_list_item_2
Vasanthi
That is the one.
Mark M.
I guess I do not understand your question, then
Vasanthi
I thought if you have more than one widget in a layout, the root has to be a layout
Mark M.
no
Vasanthi
Sorry, my laptop is very slow..
So, there is no rule that a layout has to be the root element?
Mark M.
or, rather, it depends upon what you mean by "the root has to be a layout"
Vasanthi
Now I am confused
Mark M.
there are many things in Android that use the term "layout"
with respect to TwoLineListItem, it is a (now deprecated) subclass of RelativeLayout
9:05 AM
Vasanthi
OK, now I understand.
Mark M.
if by "a layout has to be the root element", you mean "a Java class that ends in Layout has to be the root element", that is most certainly not the case
Vasanthi
Yup, now I understand. Thank you.
Mark M.
the root view element of a layout resource file could be a <fragment>, a <ViewPager>, a <TextView>, etc.
Vasanthi
OK. Can it be a class I have extended from one of the Layout classes?
Mark M.
I do not know what "one of the Layout classes" means
Vasanthi
Sorry for my wording. a widget extending one of the Layouts?
Mark M.
I do not know what "one of the Layouts" means
Vasanthi
for e.g.RelativeLayout or LinearLayout
Mark M.
try asking a question that does not involve the word "layout" used on its own, as there are many things in Android that are called "layouts"
those classes are not magic
9:10 AM
Mark M.
in a layout XML resource file, the parent of view element is going to be a subclass of ViewGroup in most cases
RelativeLayout happens to inherit from ViewGroup
ViewPager happens to inherit from ViewGroup
Vasanthi
Now, I understand.
That has cleared my doubt.
Mark M.
some subclasses of ViewGroup do not use child elements in layout XML resource files (e.g., ListView)
Vasanthi
2. What will happen if we don’t use Adapters? Say for e.g. can I have a list of items and display them in a ListView? What does the Array Adapter provide us?
Sorry.
Mark M.
"can I have a list of items and display them in a ListView?" -- if you have an adapter somewhere, yes
Refael O.
has entered the room
Vasanthi
Hi Rafael
Mark M.
an AdapterView, like ListView, works with Adapter objects to determine its contents
(BTW, hello, Refael -- I will be with you in a moment!)
Refael O.
Hi Vasanthi, Mark :)
Vasanthi
Mark, I am trying to digest what you have written, so will take a few mins.
Mark M.
OK, let me take a question from Refael in the meantime, and I will be back with you shortly
Refael: your turn! do you have a question?
Vasanthi
OK, thank you.
Refael O.
actually mark I have 3 :)
Mark M.
give me the first one for starters
9:15 AM
Refael O.
sure, ok so first off I would like to ask, I was following your github project, it gave me TONS of help, the one regarding AlarmManager with the OnBoot receiver
I am using that code to start an alarm manager on repeat, that opens a service that runs a few actions for a few seconds and then closes. the alarm repeats every 10 minutes.
problem is, if my app crash, the alarm stops repeating itself
I've been doing some digging and I have no good idea as to how to solve it
Mark M.
what method are you calling on AlarmManager to set up the alarm?
Refael O.
one sec
alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()+10000, TIME, pi);
TIME is 10 minutes
pi is my PendingIntent
Mark M.
I am not aware that an unhandled exception would unschedule an alarm
though you are the second person to mention this behavior in the past week or so
9:20 AM
Mark M.
I'll need to run some experiments to see if I can reproduce the effect
Refael O.
every 10 minutes my service runs and among other things it writes a log into a .txt file of the exact time it did it's job
for some reason I noticed when i'm crashing
the alarm stops
Mark M.
what version(s) of Android are you seeing this on, and what is your targetSdkVersion?
Refael O.
minSdk 14, targetSdk 21
I am testing it on the latest android version, on Nexus 6
Mark M.
OK, I'll run some tests as part of my overall "OMG M!" battery of work I need to get done
let me take a question from Vasanthi, and I'll be back with you in a bit
Vasanthi: your turn! do you have a question?
Refael O.
sure thing
Vasanthi
Yes, have some more. So, according to your answer about adapters, without an adapter, I can't display a list of items in a view?
Mark M.
to use an AdapterView, you need an Adapter
you can use RecyclerView, but it needs a RecyclerView.Adapter
9:25 AM
Vasanthi
OK. What does the Array Adapter provide us? Does it provide pagination?
Or is the pagination provided by the ListView that I am using?
Mark M.
neither; there is no pagination
presumably, you are a subscriber to my book (by virtue of being in this chat)
Vasanthi
YES.
Mark M.
then I suggest that you read "AdapterViews and Adapter"
it starts on page 249 of Version 6.6 of the book
Vasanthi
Yes, I have read that chapter and did the examples as well.
Mark M.
then I don't know what I can tell you
Vasanthi
According to page 233, ListView knows how to scroll. Then why is my ListViewDemo not scrolling?
Mark M.
perhaps you don't have enough data that it needs to scroll
Vasanthi
No, I have more items than what it displays.
Mark M.
then there is a problem with your device/emulator, or something
Vasanthi
I am using the emulator. If I want to debug, can I debug? Where should I place the break point?
Mark M.
I have no idea
Vasanthi
OK. I have few more questions, so if you want to answer Refael's and come back to me?
9:30 AM
Mark M.
OK
Refael: your turn! do you have another question?
Refael O.
yup
Another problem I've been having this week is with design, I need to create a facebook like card item, but the whole card has to present an imageview, and it needs to have rounded corners, and a shadow
Once again, I never come to you with a problem before I got my hands really dirty first..
Mark M.
sounds like a CardView wrapped around an ImageView
Refael O.
How am I supposed to also get rounded corners and shadow too? I tried several way that I saw on stackoverflow, none of them seemed to work
Mark M.
CardView has rounded corners and a shadow
Refael O.
CardView?
googling
Mark M.
it came out as part of the Android Support package last yaer
er, year
it's a stock implementation of the card-style UI that you describe, as a subclass of FrameLayout (IIRC)
9:35 AM
Mark M.
on Android 5.0+, it uses the system-supplied elevation-based drop shadow
on older devices, it emulates a drop-shadow using a nine-patch PNG or something
Refael O.
wow, never heard of it before, and didn't found any trace of it in my search..
Mark M.
I have some examples of it in my RecyclerView chapter
it's pretty much just a decorating container class -- wrap it around something else to give it the card-like look
Refael O.
yeah I saw the elevation one, works really well, but I have to support threw to api 14
hmmm so, wait, cardview can be supported to api 14?
Mark M.
it works back to API Level 7
Refael O.
wow amazing
looks neat
Mark M.
anyway, it's worth trying for your use case
Refael O.
ok so thats good for me, ill play around with it, Vasanthi? you're up? or should I fire away my 3rd question?
Vasanthi
Yup.
Mark M.
Vasanthi: your turn! do you have another question?
Vasanthi
the ArrayAdaptor’s getView
a. What are the parameters int position (I assume that it is the position of chosen item within the list), View convertView and ViewGroup parent ?
Mark M.
again, this is covered in the chapter that you read
position is the index into your collection of model data
Vasanthi
Just wanted to figure out whether this gets called for for each and every item in the list to be displayed?
Mark M.
convertView is either null or a previous View that you returned from an earlier call to getView(), for recycling purposes
parent is the ListView itself
yes, it is called for each item in the list
at least, when those need to be shown, or possibly cached
Vasanthi
Thank you.
Its Refael's turn
Mark M.
so, in a 25-item ListView, where 8 rows are visible, getView() will be called at the outset 8+ times, but not all 25
9:40 AM
Vasanthi
OK.
Mark M.
Refael: back to you!
Refael O.
so, my last question.. I have a layout in my main screen, I need to present a list of users inside those card views with just talked about, the list view is vertical, my problem is.. at the top of that screen I need to have another listview, this one is horizontal, and it has only 10 items displaying my top10 users. I'm wrapping all that screen in a scrollview so I can scroll the entire screen down.
but that's creating a problem using the horizontal scrolling
Mark M.
have the horizontal thingy be a row in the ListView
Refael O.
you scroll to the sides and also pull the scrollview down/up on the same time
Mark M.
rather than wrapping the whole structure in a ScrollView
or use addHeaderView() on the ListView to add your horizontal thingy
Refael O.
hmm, interesting approach
you're just brilliant Mark! how come I didn't think of it
Mark M.
I will go to great lengths to avoid trying to do the touch event hacking necessary to have a vertically scrollable thingy in a ScrollView
now, that may not completely solve your problem, but it gets rid of one item (the ScrollView) that's fighting over the touch events
Refael O.
yeah, but i will also be able to scroll down in that list
9:45 AM
Mark M.
it may clear up your problem entirely, or you may still have issues, because ListView interferes with the horizontal thingy's touch events too
I haven't tried putting horizontally-scrollable content into a ListView, so I don't know how well that works
Refael O.
ok, i'll try that and see for myself =]
as for the first question I had, regarding the alarm manager, is there a way to check if an alarm manager is now active?
Mark M.
adb shell dumpsys alarm
it will show you all scheduled alarms
if yours is scheduled, it will show up in the list
note that in your case, setRepeating() is inexact
Refael O.
would you recommend that as a solution? to check if there's a scheduled alarm, and if not, then to reschedule?
Mark M.
oh, I thought you meant for debugging
I am not aware of a reliable way to determine if your alarm exists at runtime
and, given changes coming in M, frankly, the whole "do stuff periodically in the background" area is a serious mess
Refael O.
hmm, then how would you approach such a problem? I only run this schedule once when user signs up, and then the only time it goes back is after reboot, I restart the alarm OnBoot..
9:50 AM
Refael O.
and M has a lot of time until it reaches market, I am not worried about this yet ;]
Mark M.
well, my old recommendation would be to not only log your events, but check those logs
if the last time you got control was plausible (e.g., you want every 10 minutes, you last got control 8 minutes ago), you just continue on
if the last time you got control is implausible (e.g., you want every 10 minutes, you last got control two weeks ago), you set up your alarms again
you need this for Force Stop at minimum
and, apparently, in some unhandled exception scenarios
Refael O.
hmmm
that's actually a decent fix
Mark M.
M invalidates this technique, though
let me take a question from Vasanthi, and if there's time, I'll be back with you before the chat ends
Vasanthi: any last questions?
Vasanthi
It is about the min requirement for the system to run Android Studio. My laptop is extremely slow once I start Android Studio
My laptop has Intel core i3-3217U CPU at 1.80GHz smart cache 3MB with installed memory 4.0GB (3.89GB usable) 64bit op sys windows 8.1. Disk space available 340 GB.
Mark M.
that's pretty light
Vasanthi
View paste
My colleague's laptop is Intel core i5-2410M cpu @ 2.30 GHz smart cache 3MB
6 GB mem
64 bit is
 even that runs pretty slow.
Mark M.
I have a high-end Core i7, 8GB of RAM, and Linux, and it runs fairly well
9:55 AM
Vasanthi
I have looked at what your book say
Is yours a laptop?
Mark M.
yes
Vasanthi
I was not sure about buying an i7 laptop as I read that it gets heated up due to turbo boost
Mark M.
that probably depends on the notebook model
I rarely have mine actually in my lap, but from what I can tell, it doesn't get ridiculously hot
Vasanthi
Which model would you recommend?
Mark M.
I have not really looked at current models
mine is a few-years-old Dell
Vasanthi
OK. The Linux, do I need to install that?
Mark M.
because CPUs just haven't gotten any better, and I can put in my own SSD, so until 8GB becomes a limiting factor, this will suffice
you don't need to
plenty of people develop on Windows
I think it runs a bit leaner in terms of RAM usage than do modern versions of Windows
Vasanthi
Yes, I thought so.
Mark M.
Refael: any last questions?
Vasanthi
Thank you very much, Mark.
Mark M.
you're welcome!
Refael O.
Mark, you were incredibly helpful as always, your tips are gold!
thanks a lot !
Mark M.
you too are welcome!
10:00 AM
Refael O.
btw , are you in Google I/O ?
Mark M.
no, I am not at I|O
here in my office
Refael O.
nothing like home then =)
Mark M.
watched some of the I|O live streams yesterday, and will do so again today
it's a lot less crowded here :-)
Refael O.
yeah me too, been pretty nice to watch
Mark M.
that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
Vasanthi
Mark, the answers to my first few questions aren't visible now. Is there a way, I could get them?
Refael O.
okie, i'll be leaving. thanks a lot again Mark
Mark M.
the next chat is Tuesday, also at 9am US Eastern
Vasanthi: visit https://commonsware.com/office-hours/ in a few minutes, and you can get access to the whole chat transcript
have a pleasant day, all!
Vasanthi
Thank you, Mark. Bye to Refael and you.
Vasanthi
has left the room
Refael O.
has left the room
Mark M.
turned off guest access

Wednesday, May 27

 

Office Hours

People in this transcript

  • Mark Murphy
  • Refael Ozeri
  • Vasanthi