Office Hours — Today, November 4

Yesterday, November 3

Nov 4
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Harry
has entered the room
Harry
Hello Mark
Mark M.
hello, Harry!
how can I help you today?
4:00 PM
Randall M.
has entered the room
Mark M.
hello, Randall -- Harry beat you here by a few moments, so I'll take a question from him first, then turn to you shortly
Randall M.
No worries.
Mark M.
Harry: do you have a question?
Harry
yes
sorry give me a min
Mark M.
Harry: let me take a question from Randall, then, and I'll be back with you in a few minutes
Randall: your turn! do you have a question?
Harry
ol
ok
Randall M.
Yeah, typing it out...
I'm running into some performance problems processing data that I'm receiving from a Bluetooth Low Energy device. The device device sends a chunk of data every second; I've registered the BluetoothGattCallback from a service (just like the Google Android sample code for BLE works). The data needs to be processed in a background thread (which I already have running), but there seems to be a bottle neck in creating the Message needed to hand the data off to the thread Handler.
It is possible to register the callback on a specific thread, so that I can eliminate that extra step?
4:05 PM
Mark M.
um, I have not used any of the Bluetooth APIs
Randall M.
(Normally, I'd just go ahead and try it, but it involves changing a lot of existing code to make it happen, so before I go to all that work, I want to see if it's even possible.)
What about a broadcast receiver in general? Can a receiver be registered on a specific thread?
Mark M.
no, a BroadcastReceiver is always called (in onReceive()) on the main application thread
"there seems to be a bottle neck in creating the Message needed to hand the data off to the thread Handler" -- how have you determined this?
Randall M.
By watching events that happen on the device; they are tagged in the data block sent to the phone, and it can be minutes before the phone reacts to the tagged event that it received.
Mark M.
um, but that seems to be a lot higher level than "creating the Message"
Randall M.
E.g., there's a button on the BLE device; pressing it should (nearly) immediately cause the phone to react and handle the situation.
Mark M.
yes, but "creating the Message" (which I am interpreting as call obtain() on Message) should be very cheap
other than synchronizing on access to its object pool, we're talking on the order of 10 lines of code
Randall M.
A complete message sent from the device is nearly 1KB, but is broken up in to like 120byte blocks by BLE; so all the parts are put into a Message that gets sent to the thread Handler, and my theory is that the queue of Messages is getting backed up.
4:10 PM
Mark M.
ah, now that's a bit different
creating the Message and *processing* the Message are separate things
Randall M.
Let me see if I still have a trace file lying around...
Mark M.
is this a Handler tied to a separate HandlerThread of yours?
Randall M.
yes.
Crap, it appears I've cleaned up all the trace files.
Mark M.
you might consider calling setMessageLogging() on the Looper
Randall M.
When I profiled the app, I was getting red for stuff related to the Message queue.
My processing showed no performance hits.
So I was trying to streamline how my processing gets the data in the first place.
Mark M.
I haven't had a lot of luck trying to use Traceview and kin with Looper
which is why I tend to focus on logging for that
Randall M.
And what information can I glean from that?
Mark M.
since we can achieve 60fps and better using a Looper on the main application thread, Looper/Message/MessageQueue/HandlerThread are not intrinsically slow
I mean, the whole UI is driven by that stuff
Randall M.
Hmmm....OK. So maybe I'm chasing a red herring.
Mark M.
possibly
personally, I try to minimize my use of them in the first place, preferring ThreadPoolExecutor and stuff
4:15 PM
Mark M.
let me take Harry's question, and I'll be back to you in a bit
Harry: your turn!
Randall M.
OK. Thanks.
Harry
I
Hi
I am facing alot of problem including parse.com in my app
I have tried all the solutions on stackoverflow
Error:A problem occurred configuring project ':app'. > Could not resolve all dependencies for configuration ':app:_debugCompile'. > Could not resolve com.parse.bolts:bolts-android:1.2.1. Required by: Ribbit:app:unspecified > Could not GET 'https://jcenter.bintray.com/com/parse/bolts/bol...;. > peer not authenticated
This is the error I am getting while using it
Mark M.
um, well, I have never used Parse
"peer not authenticated" seems to be an HTTPS issue with JCenter
I was under the impression that this was a temporary sort of issue that clears up after a while, perhaps due to problems with the Bintray servers
4:20 PM
Mark M.
if you are getting this consistently, you might need to change stuff in build.gradle to use http:// instead of https:// for JCenter
or, add mavenCentral() as an option, and see if you can pull in Parse from there
Harry
I have used mavenCentral
but still getting the error
Mark M.
have you tried accessing the URL that is failing in a Web browser?
Harry
I have one more doubt, sometimes we just declare dependency in build.gradle but sometimes we download library and include in lib folder, whats the diff between two approaches?
Mark M.
BTW, I am assuming this is from you: https://teamtreehouse.com/community/gradle-buil...
Harry
thats my question
Mark M.
using libs/ is for bare JARs that are not part of any artifact repository like Maven Central or JCenter
Harry
I have asked there as well
Mark M.
it came up in a Google search while I was poking around for ideas for your question
have you tried visiting https://jcenter.bintray.com/com/parse/bolts/bol... in a regular Web browser?
4:25 PM
Harry
I am getting bolts-android-1.2.1.pom file
Mark M.
OK, so the problem is not a general networking one -- it must be tied specifically to Gradle and your JVM on your development machine
if you use a proxy server in your Web browser, you will need to teach Gradle how to use that
Harry
seems so
Mark M.
and, it's possible you will need to fuss around with SSL certificates for the JVM, if whatever JVM that you are using lacks the right root certificates for JCenter's SSL connection
beyond that, I don't have a lot of advice for you -- sorry
Harry
is it given in your book?
Mark M.
no, I do not cover advanced Gradle configuration like that
as it's not really tied to Android
Harry
oks
Mark M.
let me take another question from Randall, and I will be back with you in a bit
Randall: your turn! do you have another question?
4:30 PM
Mark M.
Randall: if you come up with another question, chime in and let me know
Harry: back to you, if you have another questoin
er, question
Harry
I will try to run my project on other machine and see if it works
Mark M.
OK
if either of you have another question, go right ahead
Stephen P.
has entered the room
Harry
thanks
I am good for today
Mark M.
hello, Stephen!
Stephen P.
Hi all
Mark M.
Harry: OK
Stephen P.
So, I am new here
Mark M.
Stephen: the others have all had chances to ask questions, so it's your turn -- do you have a question?
4:35 PM
Stephen P.
Actually I do
Mark M.
go right ahead!
Randall M.
Thanks, Mark...I'm off to find a different herring... :)
Mark M.
(Randall: OK, happy herring hunting!)
Stephen P.
I am new to Android and currently working on an App for taking Selfies. I noticed when I click on the back button after adding a new item to the adapter, it reloads the list displaying the previous items. How can I fix this?
Mark M.
what do you mean by "reloads the list"?
Stephen P.
I mean the list if itens in the ListView
Mark M.
what do you mean by "reloads"?
Stephen P.
I mean when I press the back button, instead of the app to exit, it displays the ListView again but this time with the items less the one I just added
If it was only one I added then the screen will be blank
So I have to press the back button twice before the app exists
4:40 PM
Mark M.
um, well, that's kinda normal
Stephen P.
I see..
Mark M.
I am interpreting this as you have two activities, A (with a ListView) and B (doing something else)
A starts B
the user then presses BACK, returning to A
and it takes another BACK press to finish A and return to whatever started your app
Stephen P.
Yes
Mark M.
then that's perfectly normal
it works the same as the Web
you do a Google search and click on a search result link, going to a site's home page
you then click on a link on that home page to some interior page of the site
you then press BACK
on most Web sites, you will be at the site's home page, not the Google search results
Stephen P.
Yes I understand that, I come from a web background
Mark M.
so, why would the proper flow here be for pressing BACK in B to exit the app?
I'm not saying that you're wrong, or that what you want is not possible, but I want to understand why what you want makes sense from the user's standpoint
4:45 PM
Stephen P.
Its just that in my case I was wondering because the way it works is that MyListActivity has a floating button which calls the Camera app, takes a picture and then on ActivityResult I pass my object to the Adapter. Then when the adapter is notified, my ListView is updated
Mark M.
that sounds fine -- why would you want to exit your app when the picture is taken?
or am I misunderstanding your problem?
Stephen P.
Not when the picture is taken but after the ListView has been updated
Mark M.
OK, so let me see if I have this right:
you have an Activity A, that shows a ListView with a list of pictures (or something), and a FAB
you click the FAB, and you open a camera app to take a picture
in onActivityResult(), you update the ListView
Stephen P.
Correct
Correct
Mark M.
you press BACK... and you're saying you are seeing Activity A again, with a different list?
Stephen P.
Exactly!
Mark M.
then you have an extra startActivity() call, starting up Activity A, that you don't need, somewhere
what you're describing sounds like you have two instances of Activity A floating around
your onActivityResult() is updating the ListView of the second instance
Stephen P.
I see. I didn't think of that
Mark M.
pressing BACK returns you to a previous, older instance
Stephen P.
Yes, that is what is happening
4:50 PM
Randall M.
has left the room
Mark M.
you will need to track down the places where you are starting up this activity and determine how you are getting that second instance
for example, onActivityResult() should not be calling startActivity() to start up a new instance of this activity
Stephen P.
Actually I am not doing that
Mark M.
that was just a thought as to one place where this might be occuring
Stephen P.
I understand but you have given me something to think about
Thank you.
Mark M.
you are very welcome
Stephen P.
I am using Android Studio, I will try and step through again and hopefully get to see what the issue is
funny enough it happens only once and that is immediately after adding a new item. Subsequently it work normally
4:55 PM
Mark M.
that would suggest that somewhere during startup, you are accidentally creating that second instance, but then all future work remains tied to that second instance (until the user presses BACK to exit it)
Stephen P.
I am inclined to believe you. It really does look like that is what is happening
Thank you so much. When is the next Office hours?
Mark M.
tomorrow, at 7:30pm US Eastern
note that the transcripts for the chats are posted at https://commonsware.com/office-hours/
this chat's transcript will be added there shortly
Stephen P.
Okay, I will probably have more questions then. Thanks and bye for now
5:00 PM
Stephen P.
has left the room
Mark M.
that's a wrap for today's chat
have a pleasant day!
Harry
has left the room
Mark M.
turned off guest access

Yesterday, November 3

 

Office Hours

People in this transcript

  • Harry
  • Mark Murphy
  • Randall Meadows
  • Stephen Popoola