Office Hours — Today, October 24

Friday, October 20

Oct 24
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
Ahmed A.
has entered the room
Ahmed A.
Hi Mark
Mark M.
hello, Ahmed!
how can I help you today?
4:00 PM
Ahmed A.
I have few questions about scanning wifi networks scanning using Wifimanager
Mark M.
I have never done that, so I may not be of much use, but you're welcome to ask!
Ahmed A.
I am working on a project that is using 2 BroadcastReceivers
one to receive the scanresult and desplay them on the main activity every 2 secs
and the other to write them to a DB every second
Susheel
has entered the room
Susheel
Hi Mark and Ahmed
Mark M.
(BTW, hello, Susheel -- I will be with you shortly!)
Ahmed A.
Hi Susheel
Susheel
Sure thanks
Ahmed A.
I am using Handlers to create timers
4:05 PM
Ahmed A.
what happens is each of Broadcastreceivers receives results every 5 secs
I realize that the results of readings vary but what happens seems like the reading interval is set to 5 or sometimes 6 seconds
Mark M.
I would imagine that the speed of a scan will depend on a lot of factors, not the least of which being the capabilities of the hardware
Ahmed A.
Yes I see.
4:10 PM
Mark M.
what is your question?
Ahmed A.
I used a countdown timer in the past and used startscan in each onTick(each 1 sec) it worked fine but caused too much work on the main thread.
Mark M.
there are several Wi-Fi scanners in F-Droid, all of which are open source
you might look into how they are handling it
off the cuff, rather than initiating a scan every X seconds, I would initiate a scan X seconds after the previous scan ended
after all, unless you're in a fast-moving car, the details of the available WiFi networks does not change very frequently
4:15 PM
Mark M.
anyway, let me take a question from Susheel, and I will return to you in a bit for any additional questions
Ahmed A.
Thanks for this suggestion. I will try it
Mark M.
Susheel: your turn! do you have a question?
Ahmed A.
Yes sure.
Susheel
I do. Thanks.
I am calling startactivityforresult from two different fragments but I have onactivityresult implementation only in one. I am trying to figure out how to have the same onactivityresult method callback for both instances. I think the only way to do that is by overriding onactivityresult in the parent fragment/activity of the first two fragments. Am I right?
Mark M.
if the fragments called getActivity().startActivityForResult(), the result would be delivered to the activity's onActivityResult()
if a fragment calls startActivityForResult() on itself, the result goes to it, and there's nothing that you can do about that AFAIK
4:20 PM
Susheel
Right. So I have one fragment A. I am creating a dialogfragment B and these are the two places I am calling the startactivityforresult from. Even though I am creating the dialogfragment at some place in fragment A, that will still mean that onactivityresult can be overriden in one fragment only, correct?
Mark M.
only if you are calling startActivityForResult() on the same thing
the result goes to whatever it is that you call startActivityForResult() on
now, the *business logic* could be in one place, where different onActivityForResult() methods turn around and call some central method for handling the result
Susheel
Gotcha. So the way to work this issue would be to return the result to the hosting activity and then pass down the results to the fragments, right?
Mark M.
well, personally, I'm not a fan of fragments starting activities in general -- I think that's an activity responsibility
Susheel
True. Working with legacy code here. Haha.
Mark M.
but, yes, one solution is to have both fragments call startActivityForResult() on the activity, and have the activity forward the result
Susheel
Cool
I am wondering if there's any other way to do it. But that would mean a lot more coupling.
Working with legacy code really brings the best and worst out of developers
Mark M.
anything older than two weeks is legacy code :-)
4:25 PM
Susheel
This code is 4 years old. It's ancient.
4:25 PM
Mark M.
let me take another question from Ahmed, and I'll be back with you in a bit
Susheel
Sure.
Mark M.
Ahmed: back to you! do you have another question?
Ahmed A.
Yes Mark
what is the best practice to update a list displayed on a fragment using a RecyclerView when the user deletes an item
Mark M.
ummm... call notifyItemRemoved() on the RecyclerView.Adapter, if that's what you mean
4:30 PM
Mark M.
I am not certain if that is what you mean, though
Ahmed A.
In this case, do I need to recreate the adapter and call notifyItemRemoved() when the user taps the OK button on the Deletion confirmation dialog?
Mark M.
if the adapter already exists, no
you tell the adapter to remove item X
the adapter removes it from whatever it is using for its data (e.g., remove it from the ArrayList)
and the adapter calls notifyItemRemoved()
Ahmed A.
Yes It is already there and there is a deletion icon for each item
Cool.
Mark M.
let me take another question from Susheel, and I will return to you in a little while
Susheel: your turn! do you have another question?
Ahmed A.
Sure
Susheel
Yes. I have been reading about staticlayout recently. Apparently, if you are not changing text after setting it once to textview it is better to use a staticlayout and just use canvas to draw it. This is done for highly performant apps.
4:35 PM
Susheel
Stock staticlayout doesn't have a helper method for setting number of lines for text though. They have a staticlayout builder class that allows this but is available only for API levels greater than 23.
This article talks about how to measure performance in the form of computing time. https://medium.com/@programmerr47/recyclerview-...
But I do not know how to start the tool the author is talking about.
Mark M.
the author is using method tracing, but not from Android Studio
4:40 PM
Mark M.
the screenshots are from the old one from Eclipse or perhaps the Android Device Monitor
I have material on method tracing in the book, but you can capture a trace from the Android Monitor tool pane inside Android Studio
switch from logcat to the Monitors sub-tab
in the CPU monitor area's toolbar, the stopwatch icon starts and stops method tracing
or, there are methods on the Debug class to start/stop tracing programmatically
Susheel
perfect. Have you used staticlayouts before? Do you recommend using or do you see potential problems?
Mark M.
the UI that Android Studio uses is quite a bit different (and, IMHO, sucks), but it has the same basic objectie
er, objective
I have not used StaticLayout
Susheel
okay
Mark M.
I haven't seen dropped frames that I attributed to TextView, so I haven't bothered
Susheel
Gotcha.
Mark M.
unless you have clear problems with jank, StaticLayout strikes me as premature optimization
Susheel
Really?
Okay
Mark M.
only optimize what needs to be optimized
beyond that, there's probably lots of other work that could get done (tightening security, adding features, etc.)
but, that's me
4:45 PM
Mark M.
let me switch back to Ahmed, and I'll try to return to you before the chat end
er, ends
Ahmed: your turn! do you have another question>?
er, question?
Ahmed A.
Yes
Mark M.
(sheesh, I can't type today...)
Ahmed A.
Do you recommend a library to create a CSV and XML from POJO something similar to Gson? I tried Jackson but unfortunately, I failed to have it work.
Mark M.
I haven't had a need to generate CSV, and the last time I generated XML from Android, I think that I just used XmlSerializer from the Android SDK
and I have not researched libraries for these
so, I do not have any particular recommendations -- sorry!
Ahmed A.
Fair enough
Susheel
Thanks Mark. I am good.
Ahmed A.
Can I ask a last question?
4:50 PM
Mark M.
Ahmed: sure, go ahead -- we still have 10 minutes
(Susheel: OK, thanks!)
Ahmed A.
I am preparing to publish my first app but still need to test it on old versions. Because it uses Wifi stuff, I need real devices. Are you aware of some platform or online service to make such kind of test?
Mark M.
that depends on how you want to go about it
if your objective is to literally test the WiFi-related code, you're pretty much out of luck AFAIK
if your objective is to test the app overall, then a typical approach is to architect your app such that the WifiManager-specific bits can be replaced by mock data, then test the app with the mocks
4:55 PM
Mark M.
that will not test the WifiManager-specific bits, by definition
but it would test other aspects of your app
personally, I have accumulated a lot of hardware over the years, and so I don't use these services, as I have pretty much what I need here
Ahmed A.
I think I need to collect different devices because my app's goal is to provide info for users to study the abilities of different devices and OS versions in capturing and dealing with wifi signals.
Mark M.
then ask your friends to test your app :-)
Ahmed A.
Thanks a million Mark
Mark M.
you're very welcome
Ahmed A.
Have a wonderful day Mark and Susheel
Mark M.
you too!
5:00 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 Thursday at 7:30pm US Eastern
have a pleasant day!
Ahmed A.
has left the room
Susheel
has left the room
Mark M.
turned off guest access

Friday, October 20

 

Office Hours

People in this transcript

  • Ahmed Alnabhan
  • Mark Murphy
  • Susheel