Office Hours — Today, July 21

Yesterday, July 20

Jul 21
7:25 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:55 PM
Steve S.
has entered the room
Mark M.
hello, Steve!
Steve S.
Hi, Mark!
Mark M.
how can I help you today?
Steve S.
Let me paste in my question:
View paste
In my app, the user can select a recipe from a list. When he does, a RecyclerView is displayed. The rows of the RecyclerView contain an EditText and a Spinner that display the stored values of recipe parameters and allow the user to change them.

I am wondering how to handle rotations. It seems like the ideal strategy would be to preserve the changes the user makes. The only way I can see to do this would be to use a TextWatcher for the EditText and an onClickListener for the Spinner to detect changes as the user makes them and then to persist those changes. 

Is this a reasonable strategy? Is there a better way to do this? Would it be reasonable not to keep track of those changes and to allow them to be lost if the user rotates the device?
Mark M.
if you mean rotating the screen, that's not your biggest problem
Steve S.
ok
Mark M.
your biggest problem is recycling in RecyclerView
Steve S.
ok
Mark M.
when the user scrolls, and your row gets recycled, you need to be able to save off the old data before you blow it away by filling in the widgets with the new position's data
how you tackle that will tie into how you tackle orientation changes
Blue D.
has entered the room
Mark M.
one approach is to do what you say: use continuous listeners to update your view model (or whatever) with the changed data
Steve S.
I see. I should mention that there are never more than six cycles, and no scrolling is needed
ok
Mark M.
(Blue: hi! I will be with you shortly!)
Blue D.
Sure!
Mark M.
never say "no scrolling is needed" until you've tested on a device whose screen is the size of a postage stamp :-)
or, to flip it around, if you are sure that no scrolling is needed, get rid of the RecyclerView
Steve S.
ok
Mark M.
as the point behind RecyclerView is to recycle views during scrolling and similar events
anyway, back to your problem
the listener approach can work, assuming that the widgets offer the desired listeners
and in your case, they do
Steve S.
ok
8:00 PM
Mark M.
so long as you are retaining your view model (or whatever) across configuration changes, you are OK
that could be a retained fragment, onRetainNonConfigurationInstance(), the new ViewModel stuff in the Architecture Components, a singleton POJO cache, etc.
Steve S.
ok
Mark M.
if you run into cases where the listeners are problematic, you can also keep track of state as the rows get recycled -- there's a callback for that on the Adapter, IIRC
however, then on a configuration change, you need to capture whatever data is in the on-screen widgets
the listener approach is probably easier
Steve S.
ok
Mark M.
at least in your case
Steve S.
back to your point about not using a RecyclerView
Mark M.
if you dump the RecyclerView, then you have nothing that you need to do on a configuration change, as onSaveInstanceState() processing should handle your widgets
actually, it'll handle the EditTexts, and I forget how well it handles Spinner
let me take a question from Blue, and I'll be back with you shortly
Blue: your turn! do you have a question?
Steve S.
sure
8:05 PM
Mark M.
Blue: do you have a question?
Blue, if you come up with a question, chime in and let me know
meantime, back to you, Steve
Blue D.
Hi Mark! Yes, I have small question. I have an app which has "category.HOME" and to act as a home screen. Every time I install this app, android asks me to choose the home showing the stock home app and my home app. Is there a way to make this switch and make my home app a default app without user input?
Mark M.
no, for security reasons
allowing an app to blindly take over the home screen would be bad
ransomware developers would have a field day
now, AFAIK, you should only get prompted for a fresh install, not just running your app again from the IDE
though it's been quite some time since I wrote a home screen activity, so the run-from-the-IDE behavior might have changed
did that answer your question?
Blue D.
what is the "run -from -the-IDE"? is the just clicking run from the Android studio? If yes, yeah. the app is installing and opens up asking to choose between the Homes.
8:10 PM
Blue D.
What is my Home app is firmware signed?
Mark M.
really? that's unexpected
that should not change the behavior
what would change the behavior is if yours is the only home screen implementation
Blue D.
Okay. Got your point. I think that answered the question. Thank you!
Mark M.
OK
Steve: your turn! do you have another question?
Steve S.
back to your point about dumping the RecyclerView
in my first version, I in fact used a TableLayout with sixteen views (they were all edit texts).
but that was a bit complicated to manage. So someone suggested I try List/RecyclerView instead
Mark M.
what does "complicated to manage" mean?
Steve S.
The user can add and remove rows in the matrix
Mark M.
earlier, you said there was always six rows
8:15 PM
Mark M.
unless I misunderstood
Steve S.
right, i misspoke - i should have said there are never more than six rows
Mark M.
adding new rows in a TableLayout is slightly more annoying than having them in a RecyclerView
that being said, I doubt that I would use a RecyclerView in your use case, given what I know
Steve S.
ok. so perhaps in this case the TableLayout would be a better approach?
Mark M.
I would use a TableLayout or ConstraintLayout, personally (again, given what I know)
Steve S.
ok. this is very helpful
no more questions today
Thank you so much, Mark!
Mark M.
you're welcome!
Blue: your turn! do you have another question?
Steve S.
have a great rest of the day!
Steve S.
has left the room
Blue D.
Yes Mark. one last question for today.
8:20 PM
Blue D.
Yesterday, I have stackoverflow bumped a question regarding the google play silent install. I got your reply. But with experience you have could you point me in a direction where that can be achieved if you have any idea?
Mark M.
yes, we discussed this by email, after your bump request
Blue D.
Yes. So any suggestions?
Mark M.
I do not work with rooted devices
and so I have no suggestions
other than to make sure that you have your attorney's phone number handy, as Google might not like what you are proposing
Blue D.
Oh no, I am not very serious about it. I am not sure if that can be done. That is a requirement in one of my projects. So I want to know if this can be achieved. If not I can mention that its not possible.
8:25 PM
Blue D.
Okay Mark. Thank you so much for answering the questions. Thats all from me today.
Mark M.
sorry I could not be of more help on that second one
Blue D.
Thanks for trying. Have a great weekend!
Mark M.
you too!
Blue D.
has left the room
8:30 PM
Mark M.
turned off guest access

Yesterday, July 20

 

Office Hours

People in this transcript

  • Blue D
  • Mark Murphy
  • Steve S