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!
|
Mark M. |
how can I help you today?
|
Nov 4 | 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
|
Harry |
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
|
Mark M. |
Randall: your turn! do you have a question?
|
Harry |
ol
|
Harry |
ok
|
Randall M. |
Yeah, typing it out...
|
Randall M. |
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.
|
Randall M. |
It is possible to register the callback on a specific thread, so that I can eliminate that extra step?
|
Nov 4 | 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.)
|
Randall M. |
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
|
Mark M. |
"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
|
Mark M. |
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.
|
Nov 4 | 4:10 PM |
Mark M. |
ah, now that's a bit different
|
Mark M. |
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.
|
Randall M. |
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.
|
Randall M. |
My processing showed no performance hits.
|
Randall M. |
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
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
personally, I try to minimize my use of them in the first place, preferring ThreadPoolExecutor and stuff
|
Nov 4 | 4:15 PM |
Mark M. |
let me take Harry's question, and I'll be back to you in a bit
|
Mark M. |
Harry: your turn!
|
Randall M. |
OK. Thanks.
|
Harry |
I
|
Harry |
Hi
|
Harry |
I am facing alot of problem including parse.com in my app
|
Harry |
I have tried all the solutions on stackoverflow
|
Harry |
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
|
Harry |
This is the error I am getting while using it
|
Mark M. |
um, well, I have never used Parse
|
Mark M. |
"peer not authenticated" seems to be an HTTPS issue with JCenter
|
Mark M. |
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
|
Nov 4 | 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
|
Mark M. |
or, add mavenCentral() as an option, and see if you can pull in Parse from there
|
Harry |
I have used mavenCentral
|
Harry |
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
|
Mark M. |
have you tried visiting https://jcenter.bintray.com/com/parse/bolts/bol... in a regular Web browser?
|
Nov 4 | 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
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
Randall: your turn! do you have another question?
|
Nov 4 | 4:30 PM |
Mark M. |
Randall: if you come up with another question, chime in and let me know
|
Mark M. |
Harry: back to you, if you have another questoin
|
Mark M. |
er, question
|
Harry |
I will try to run my project on other machine and see if it works
|
Mark M. |
OK
|
Mark M. |
if either of you have another question, go right ahead
|
Stephen P. | has entered the room |
Harry |
thanks
|
Harry |
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?
|
Nov 4 | 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
|
Stephen P. |
If it was only one I added then the screen will be blank
|
Stephen P. |
So I have to press the back button twice before the app exists
|
Nov 4 | 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)
|
Mark M. |
A starts B
|
Mark M. |
the user then presses BACK, returning to A
|
Mark M. |
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
|
Mark M. |
it works the same as the Web
|
Mark M. |
you do a Google search and click on a search result link, going to a site's home page
|
Mark M. |
you then click on a link on that home page to some interior page of the site
|
Mark M. |
you then press BACK
|
Mark M. |
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?
|
Mark M. |
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
|
Nov 4 | 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?
|
Mark M. |
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:
|
Mark M. |
you have an Activity A, that shows a ListView with a list of pictures (or something), and a FAB
|
Mark M. |
you click the FAB, and you open a camera app to take a picture
|
Mark M. |
in onActivityResult(), you update the ListView
|
Stephen P. |
Correct
|
Stephen P. |
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
|
Mark M. |
what you're describing sounds like you have two instances of Activity A floating around
|
Mark M. |
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
|
Nov 4 | 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
|
Mark M. |
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
|
Stephen P. |
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
|
Stephen P. |
funny enough it happens only once and that is immediately after adding a new item. Subsequently it work normally
|
Nov 4 | 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
|
Stephen P. |
Thank you so much. When is the next Office hours?
|
Mark M. |
tomorrow, at 7:30pm US Eastern
|
Mark M. |
note that the transcripts for the chats are posted at https://commonsware.com/office-hours/
|
Mark M. |
this chat's transcript will be added there shortly
|
Stephen P. |
Okay, I will probably have more questions then. Thanks and bye for now
|
Nov 4 | 5:00 PM |
Stephen P. | has left the room |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
have a pleasant day!
|
Harry | has left the room |
Mark M. | turned off guest access |