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!
|
Mark M. |
how can I help you today?
|
Oct 24 | 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
|
Ahmed A. |
one to receive the scanresult and desplay them on the main activity every 2 secs
|
Ahmed A. |
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
|
Oct 24 | 4:05 PM |
Ahmed A. |
what happens is each of Broadcastreceivers receives results every 5 secs
|
Ahmed A. |
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.
|
Oct 24 | 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. | |
Mark M. |
there are several Wi-Fi scanners in F-Droid, all of which are open source
|
Mark M. |
you might look into how they are handling it
|
Mark M. |
off the cuff, rather than initiating a scan every X seconds, I would initiate a scan X seconds after the previous scan ended
|
Mark M. |
after all, unless you're in a fast-moving car, the details of the available WiFi networks does not change very frequently
|
Oct 24 | 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.
|
Susheel |
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()
|
Mark M. |
if a fragment calls startActivityForResult() on itself, the result goes to it, and there's nothing that you can do about that AFAIK
|
Oct 24 | 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
|
Mark M. |
the result goes to whatever it is that you call startActivityForResult() on
|
Mark M. |
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
|
Susheel |
I am wondering if there's any other way to do it. But that would mean a lot more coupling.
|
Susheel |
Working with legacy code really brings the best and worst out of developers
|
Mark M. |
anything older than two weeks is legacy code :-)
|
Oct 24 | 4:25 PM |
Susheel |
This code is 4 years old. It's ancient.
|
Oct 24 | 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
|
Ahmed A. |
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
|
Oct 24 | 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
|
Mark M. |
you tell the adapter to remove item X
|
Mark M. |
the adapter removes it from whatever it is using for its data (e.g., remove it from the ArrayList)
|
Mark M. |
and the adapter calls notifyItemRemoved()
|
Ahmed A. |
Yes It is already there and there is a deletion icon for each item
|
Ahmed A. |
Cool.
|
Mark M. |
let me take another question from Susheel, and I will return to you in a little while
|
Mark M. |
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.
|
Oct 24 | 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.
|
Susheel |
This article talks about how to measure performance in the form of computing time. https://medium.com/@programmerr47/recyclerview-...
|
Susheel |
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
|
Oct 24 | 4:40 PM |
Mark M. |
the screenshots are from the old one from Eclipse or perhaps the Android Device Monitor
|
Mark M. |
I have material on method tracing in the book, but you can capture a trace from the Android Monitor tool pane inside Android Studio
|
Mark M. |
switch from logcat to the Monitors sub-tab
|
Mark M. |
in the CPU monitor area's toolbar, the stopwatch icon starts and stops method tracing
|
Mark M. |
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
|
Mark M. |
er, objective
|
Mark M. |
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?
|
Susheel |
Okay
|
Mark M. |
only optimize what needs to be optimized
|
Mark M. |
beyond that, there's probably lots of other work that could get done (tightening security, adding features, etc.)
|
Mark M. |
but, that's me
|
Oct 24 | 4:45 PM |
Mark M. |
let me switch back to Ahmed, and I'll try to return to you before the chat end
|
Mark M. |
er, ends
|
Mark M. |
Ahmed: your turn! do you have another question>?
|
Mark M. |
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
|
Mark M. |
and I have not researched libraries for these
|
Mark M. |
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?
|
Oct 24 | 4:50 PM |
Mark M. |
Ahmed: sure, go ahead -- we still have 10 minutes
|
Mark M. |
(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
|
Mark M. |
if your objective is to literally test the WiFi-related code, you're pretty much out of luck AFAIK
|
Mark M. |
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
|
Oct 24 | 4:55 PM |
Mark M. |
that will not test the WifiManager-specific bits, by definition
|
Mark M. |
but it would test other aspects of your app
|
Mark M. |
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!
|
Oct 24 | 5:00 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Mark M. |
the next chat is Thursday at 7:30pm US Eastern
|
Mark M. |
have a pleasant day!
|
Ahmed A. | has left the room |
Susheel | has left the room |
Mark M. | turned off guest access |