Office Hours — Today, April 27

Thursday, April 16

Apr 27
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
PPartisan
has entered the room
PPartisan
Hey Mark
Mark M.
hello, PPartisan!
how can I help you today?
PPartisan
Ohh, just me :)
EGHDK
has entered the room
Mark M.
hello, EGHDK!
PPartisan
I have a question that I put up on Stack Overflow a couple of days ago regarding ways to improve edittext performance
Mark M.
ok, got a link?
PPartisan
http://stackoverflow.com/questions/29801232/edi... Here's the link - essentially I wondered whether you could offer any tips to improve load times and/or performance whilst scrolling
7:30 PM
Mark M.
well, on the whole, EditText is not designed for multi-KB prose
beyond that, you would need to look at Traceview results and see if they give you clues
I am somewhat baffled by your GPU results, though
PPartisan
I know - results vary wildly per device as well. I've noticed that when using GPU profiling on a Nexus 7 2013, the "blue" bars representing draw time have massive spikes, although performance is fine, whereas lower spec hardware doesn't show this. It's difficult for me to interpret them.
Mark M.
the downside of the GPU profiling bar chart is that it does not, on its own, give you a lot to go on
Traceview or systrace is likely to give you better results
s/is/are/
though I find systrace to be very difficult to interpret
Refael O.
has entered the room
Mark M.
with respect to your toggling on/off HW acceleration, you could play with setLayerType(), though I'll be surprised if this is the right answer for your real problem
(BTW, hello, Rafael -- I will be with you after EGHDK!)
7:35 PM
Mark M.
PPartisan: let me take questions from the others, and I will swing back to you in a few minutes
EGHDK: your turn! do you have a question?
Refael O.
Hello Mark, no problem no rush :)
PPartisan
I'll look into it. And sure :)
Mark M.
EGHDK: your turn! do you have a question?
EGHDK
Hello Mark. I'm trying to follow the testing tutorial on android tools site. "Our gradle plugin will compile source code found in src/test/java" So I put my junit4 tests in there, but I can only test the public methods though. So I want to test one of my utility classes but I have some private methods and such, but I'd still like basic junit cases for them. How would I go about it?
Mark M.
either test the private methods via public ones, or change their visibility
for example, package-private (i.e., no public/private/protected keyword) could be tested by test cases that you put into the same Java package
I am not aware of a way to test private methods from outside classes
EGHDK
No way to change the visibility of a method just for a test case though... correct?
Mark M.
though it's possible there is some standard JUnit4 trick for that
IIRC, you can bypass private restrictions via reflection
it's not something I have tried, as I usually am testing my API, not doing white-box muck-with-the-private-innards testing
but, again, there may be something in JUnit4 for it -- I haven't looked
7:40 PM
Mark M.
let me take questions from the others, and I will be back with you shortly
EGHDK
Is it standard to put test cases inside of an actual package? Like, if I wanted to test my private methods...
No problem.
Mark M.
Refael: your turn! do you have a question?
(EGHDK: Java classes are almost always in a Java package)
Refael: your turn! do you have a question?
Refael O.
Yes I do, ok, so basically I have a little UI problem, I'm download a file using the DownloadManager class. now, I got a listener that sends the total bytes downloaded to my adapter so I can update a downloading bar in the my listview item. 2 problems I'm having is.. 1. if I quit the fragment by moving to other fragment or by going to the background, when I come back I don't see my download anymore, but it's still downloading in the background.
problem 2, if I scroll down and load more items, also, same problem, the adapter refreshes and I lose my "connection" with the download
once again, it's still downloading and all, just the UI isn't working as expected
Mark M.
IMHO, DownloadManager is really for "fire-and-forget" scenarios. If you want to measure bytes-downloaded and such, why are you not downloading the file yourself?
7:45 PM
Refael O.
what do you mean by downloading it myself?
Mark M.
using HttpUrlConnection, OkHttp, etc. and downloading it yourself, perhaps via an IntentService
Refael O.
it's the first time I work with downloading files, it's the most common way I found arround the web..
hmmm, you think it would be better?
Mark M.
well, if I were writing it, and I wanted that fine-grained degree of knowledge/control, I would be downloading it myself
Refael O.
but wait, if I do so, the download will still go on in the background?
aw you said Service so ofcourse it will
Mark M.
if you do the download in the background, yes
Refael O.
ok i'll give it a try.. thanks Mark!
Mark M.
FWIW, there are several samples in the book that show downloading a PDF via an IntentService
PPartisan: back to you! do you have another question?
Refael O.
ow ill check those samples out then, thanks for the hint
PPartisan
Sure, I was just looking into setLayerType. I think it could prove useful, although really I would need to know why switching HW Acceleration on/off in the first place improved performance on setText, so I could only target those devices. I know we touched on this before, but can you think of why disabling HW acceleration in this way may help?
only target those devices where it provided a performance boost*
Mark M.
off the cuff, no
7:50 PM
Mark M.
I put a comment on your SO post: you might want to toss together a sample app that reproduces what you are seeing
PPartisan
Ok, I think I will. I noticed someone else on SO was getting alot of attention with a similar problem too.
Until ten though, is there a more common method on android for dealing with large amounts of editable text?
aside from EditText I mean.
Mark M.
use smaller text? :-)
PPartisan
:D
Mark M.
I mean, you can go with a WebView and something that does editing in it
PPartisan
Ok
Mark M.
that may be a "whack-a-mole" situation, fixing some problems and causing new and exciting ones
PPartisan
Ha - is there anything in the book on using WebView in this way?
Mark M.
no, sorry
that's a rich text editor that uses a WebView for its implementation
I have not tried it, so YMMV
let me take questions from the others, and I will be back with you in a bit
PPartisan
Thanks. I have another question, but it's pretty broad, so I'm happy to wait
ok
Mark M.
EGHDK: back to you! do you have another question?
7:55 PM
EGHDK
I'm reading a patterns book and they toss around the word interface a lot, but it's not a java specific book. So I don't think they mean interface in the "implements Interface" kind of way. What does interface mean in programming? Just because the first principle in the book is "Program to an interface"\
Mark M.
um, well, it's a word that has multiple uses and meanings
hence, I cannot really answer your question very well
from that heading, I would assume that they mean "interface" along the lines of a Java interface
IOW, try to program to have the possibility of multiple implementations of X for any X that is bigger than a breadbox
which implies that X, X', X'', etc. all implement a common interface that you code to
let me take questions from the others, and I will be back with you in a bit
Refael: back to you! do you have another question?
8:00 PM
Refael O.
has left the room
Mark M.
OK, I guess not...
PPartisan: back to you!
PPartisan
I had a go at using the ARC welder Chrome app today, and as it's quite new out I was hardly able to find any tutorials or information about it beyond the short google documentation. I wondered whether you'd had any exposure with it and knew of a good place to look for more info about optimising Android apps for use with ARC etc?
Mark M.
you mean, besides the extensive chapter that I have in the latest version of the book?
PPartisan
Ahh...I missed that! I may not have the latest version
nevermind
Mark M.
it's in Version 6.6
came out a bit less than two weeks ago
ARC is definitely rough around the edges
but, it has interesting possibilities
the chapter is a tad short of 30 pages
starts at page 3066 of the PDF
PPartisan
That's brilliant news
8:05 PM
Mark M.
beyond that, keep tabs on the google-chrome-arc Stack Overflow tag
8:05 PM
Mark M.
Google is providing halfway decent support there
PPartisan
I had a quick look today, only around 50questions so far - and I've just updated to v6.6, so I'll take a look
Mark M.
let me swing back to EGHDK, and I'll be back to you in a bit
EGHDK: your turn! do you have another question?
EGHDK
I'm going back to my http client question I asked a little while back. I've decided that I'm going to have a single http client in the Application class. I have two questions though regarding this design decision. First question. Should I make the Client static, because I know the application class is a singleton so it shouldn't really make a difference if the client is static or not?
Mark M.
a regular data member of an Application subclass will have the same lifetime as a static data member of any class
so, it should not much matter
at least from an object lifetime standpoint
EGHDK
So static at that point would just make it easier to use if anything?
Mark M.
what is your second question?
EGHDK
Because I can do MyApp.globalClient
Mark M.
it will be easier to reach, yes
anything with static scope needs to be used carefully, to avoid memory leaks, manage thread safety, etc.
EGHDK
2. What are the advantages or disadvantages to creating the object inline where I'm naming the variable (e.g. HttpClient globalClient = new HttpClient) or should I just do HttpClient globalClient and use Application.onCreate() to do globalClient = new HttpClient()?
Mark M.
they are equivalent
8:10 PM
Mark M.
in fact, I would expect the compiled bytecode to be identical
now, that's because you are not referring to superclass methods, but are just instantiating an object
for Android classes with onCreate()-style semantics, you would want to do it your second way
and do the initialization after super.onCreate()
EGHDK
Lost me at "now, that's because you are not referring to superclass methods, but are just instantiating an object"
Mark M.
let's look at a different scenario
you have an Activity
you want it to have a WebView for its UI
rather than inflate a layout, you're just going to use the WebView constructor
EGHDK
yep
Mark M.
from a Java standpoint, private WebView wv=new WebView(this) as a data member in an Activity is perfectly legal
however, you'll crash
because Activity is not yet ready to be used then
so, you use private WebView wv; as your data member declaration
and you use wv=new WebView(this); sometime after super.onCreate()
another variation on the theme is developers trying to use findViewById() from a data member initializer (e.g., private WebView wv=(WebView)findViewById(R.id.browser);)
that's doubly wrong, as not only is the Activity not yet ready, but you have not called setContentView() yet anyway
EGHDK
Gotcha.
So no real difference then as long as my implementation doesnt crash?
8:15 PM
Mark M.
in your case, there should be no difference
EGHDK
Thanks
Mark M.
now, I would like to point out that, for the record, using Android's HttpClient is your worst possible choice for HTTP API, as it is deprecated in Android 5.1
if you're using Apache's separate Android-friendly JAR with their HttpClient, that should be OK
and with that, let me switch back to PPartisan...
PPartisan: your turn! do you have another question?
PPartisan
I'm fine now Mark, thanks, I just found the chapter you were referring to
Mark M.
OK
EGHDK
I'm using okHttp, but apache has a separate android jar for httpclient?
Mark M.
yes, somewhere...
though the OkHttp HttpClient-compatible API may be better anyway, as you get SPDY support and such
(BTW, PPartisan, if you come up with another question, let me know)
PPartisan
ok
EGHDK
and http2!
Mark M.
yes, that's the continuation of SPDY in official form
8:25 PM
EGHDK
Mark. One more question. Is there any best practice to make sure that other members on my project only use my globalClient and don't create another httpclient somewhere else?
Mark M.
not really
EGHDK
Okay. Just wanted to make sure.
Oh actually one more question. Anyway to only compile a class in for a specific build variant?
Thinking about looking into annonations for this maybe
Mark M.
well, you can just have the source in that variant's sourceset
however, if the main sourceset refers to that class, you have a problem
EGHDK
Gotcha.
Okay. That's all for me. Thanks Mark
Mark M.
you'
8:30 PM
Mark M.
you're welcome!
8:30 PM
Mark M.
that's a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is tomorrow at the same time, 7:30pm US Eastern
have a pleasant day!
PPartisan
you too
PPartisan
has left the room
EGHDK
has left the room
Mark M.
turned off guest access

Thursday, April 16

 

Office Hours

People in this transcript

  • EGHDK
  • Mark Murphy
  • PPartisan
  • Refael Ozeri