Office Hours — Today, January 7

Tuesday, January 5

Jan 7
8:20 AM
Mark M.
has entered the room
8:25 AM
Mark M.
turned on guest access
Kai H.
has entered the room
Kai H.
Hello Mark
Mark M.
hello, Kai!
how can I help you today?
Kai H.
In one of your books, you mention that Jetpack "Navigation" is pretty much only suitable for small Apps. Does this still hold true?
Mark M.
it is fairly rigid
bigger apps tend to imply bigger teams, where some team members will not like aspects of that rigidity
bigger apps also tend to imply more "weird stuff" where the rigidity will be an impediment
Kai H.
I see
8:30 AM
Mark M.
bigger apps also tend to imply non-Android parties having significant votes, such as designers
I will probably need to revisit whatever language that I used there and make sure that it is up to date
it's not that a big app *can't* use Navigation, but it requires you to be willing to live within its limits or live with going outside of Navigation from time to time as needed
Kai H.
So is Googles idea probably "every app should have only as much navigation as Navigation can give"? Or what do you reckon?
Mark M.
I suspect that it is impractical to provide a navigation framework that is infinitely flexible
a lot of the Jetpack is Google putting its opinions out front
sudokai
has entered the room
Mark M.
Navigation is Google's opinion on how navigation should be done, within the limits of the engineering time they could put into it
Kai H.
"Why even bother then?" is my immediate thought.
Hi kai
Mark M.
(hello, sudokai -- I will be with you shortly!)
Kai: to an extent, I had the same sort of reaction
in a pure greenfield environment, such as Navigation for Compose, things feel a bit more natural
(at least in my mind)
8:35 AM
Mark M.
and having a reasonable solution out there for fragments is perfectly fine
it's just that how well Navigation handles the reality of major-project development is... I'll call it "unproven"
Kai H.
Ok
Mark M.
so, IMHO, you don't need to *avoid* Navigation, just understand that it is strongly opinionated and that those opinions may conflict with the opinions of other developers, designers, management, etc.
and the bigger the project, the more likely it is that there will be those other opinions
let me take a question from sudokai, and I'll return to you in a bit
sudokai: hi! how can I help you today?
8:40 AM
Mark M.
sudokai: do you have a question?
sudokai: if you come up with a question, chime in and let me know
in the meantime...
Kai: back to you! do you have another question?
Kai H.
Yes
I have a prepopulated db that I try to access with room. I get 0 results where I should get 18 ("SELECT * FROM mytable"). How to debug?
(Isn't that a very specific question? ;-) )
Mark M.
use Database Inspector if you are on Android Studio 4.1 or higher and confirm what the database has in it
8:45 AM
Mark M.
if it truly has zero rows, do "Clear Data" on your app in Settings (or uninstall it), then try running it again
if you still wind up with 0 rows, then your prepopulated database is not getting used
Kai H.
After deinstalling and rerunning I get a different error. Thanks :D
It seems to not have used my pre-packaged database before. I would have liked to at least have some sort of error message somewhere in between.
But I guess that's what "instant run" gives us.
Mark M.
I always avoided that, and now try very carefully to never click the "Apply Changes and Restart Activity" button
Kai H.
Isn't that the default "shift + f10" behaviour? That's what I always use.
8:50 AM
Mark M.
shift + F10, at least on Linux, is "Run"
ctrl + F10 is "Apply Changes and Restart Activity"
keybindings might vary by platform, though
Kai H.
Ok, so I just ran and it didn't use my database, apparently.
Ah well. Good to know that sometimes a reinstall is in order, apparently.
Mark M.
that's one of the reasons why I suggested seeing what is in the actual database when you were in the 0-rows state
if it shows 18 rows, then your problem is that however you are testing the 0-rows case isn't using your database
if, instead, the actual database shows 0 rows, then either Room created an empty database for you or you deleted 18 rows somewhere along the line
Kai H.
Well, after reinstalling it uses the actual database :D
Now I get "Pre-packaged database has an invalid schema: " instead, which is more to work with.
Mark M.
that's one of the bigger headaches with pre-packaged databases and Room -- keeping the schema of the pre-packaged database up to date
8:55 AM
Kai H.
View paste
The problem now is between the expected and found TableInfo (which is generated):
title=Column{name='title', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=0, defaultValue='null'}
title=Column{name='title', type='TEXT', affinity='2', notNull=false, primaryKeyPosition=0, defaultValue='null'}
Mark M.
one is set for NOT NULL and the other is not
9:00 AM
Kai H.
I didn't know that mattered X)
Mark M.
if it affects the table definition, it matters
Kai H.
So either make the Kotlin variables nullable or the rows NOT NULL in SQL, I guess?
Mark M.
you need to be consistent between the entity definitions and the schema in you pre-populated database
one way to do that is to let Room create an empty database for you, pull it off the device, and use that as the starting point for pre-population
the headache being that every time you tweak an entity, you may need to do that again
Kai H.
How would I fix this one error?
Mark M.
Step #1 would be to decide which is correct. Ignoring the actual error, logically, is a null title valid?
(what Step #2 is will depend on the answer to Step #1)
Kai H.
No, it is not. There shall only be nonNull titles.
9:05 AM
Mark M.
then the Kotlin is fine, based on your earlier statement
and your problem is in the pre-populated database, where you are allowing nulls in the title coumn
er, column
Kai H.
So I'll need to work on that.
Mark M.
yes, using your favorite SQLite client, you would need to amend that table structure to not allow nulls
Kai H.
View paste
This is strange btw, because chapter_id is denoted as a primary key in the database scheme, so it should by definition be notNull
chapter_id=Column{name='chapter_id', type='INTEGER', affinity='3', notNull=false, primaryKeyPosition=1, defaultValue='null'}, 
chapter_id=Column{name='chapter_id', type='TEXT', affinity='2', notNull=true, primaryKeyPosition=1, defaultValue='null'}},
And it's also denoted as such in the ChapterEntity
9:10 AM
Mark M.
well, you also have a problem here on type: one says INTEGER, the other says TEXT
Kai H.
Ah, I changed that already. Sorry.
Mark M.
I pretty much always let Room create the empty database for me, then populate it
Kai H.
Ok, so I'll try and do the same.
Makes scraping it with another program a little harder, but ah well.
Mark M.
if I did enough of that sort of work, I would write a tool that reads in the schema stuff written in JSON and use that as the basis for creating a compliant database off-devices
Kai H.
The things we do to use jetpack components ;-)
sudokai
Hello
Kai H.
He's alive!
Mark M.
hello, sudokai!
sudokai
Happy new year
Mark M.
sudokai: Happy New Year! how can I help you today?
sudokai
Yeah, I'm still struggling with some location updates code
The problem I now see is that I request location updates and *sometimes*, location updates just don't come in
Kai H.
Happy new year :D
sudokai
So, you request location updates with LocationManager, 1 per sec
9:15 AM
Mark M.
what provider are you using?
sudokai
Then 2 hours later, the listener has received maybe 4 coordinates
GPS
Mark M.
OK, and is this happening for you during development or only in the field?
sudokai
Both
But it's not always reproducible
Mark M.
if this were purely something you saw in production, then the problem might simply be that the device cannot receive GPS signals -- those are not available everywhere
sudokai
I see really strange stuff
Like requesting location updates with locationmanager, no updates for 5 minutes
Then switch to fused location, do the same, then switch back
voila, now it works
Or no location updates for 5 minutes, then voila, you look at the phone, now it starts working
Mark M.
fortunately, I have not needed to use GPS locations in real projects in a couple of years
sudokai
I'm aware of a GPS cold start situation
But 5-10 mins to get a fix???
Mark M.
for the "you look at the phone" problem, bear in mind that Doze mode and similar power considerations still apply
so, are you holding a partial WakeLock?
9:20 AM
sudokai
Once, I also started location updates inside a garage with no GPS signal, then went out and drove for two hours, didn't receive a single location update
Actually, this case seem to happen fairly frequently
If you start your location updates somewhere with no GPS signal, then it never recovers
> so, are you holding a partial WakeLock?
Yep
ForegroundService type=location too
Mark M.
sorry, but I do not have a lot of advice for you
sudokai
Okay, yeah no problem
It really sucks
Don't work with Android and GPS
:)
Mark M.
OK, we're running low on chat time -- if either of you have questions, go ahead!
Kai H.
I have looked at a couple of (open source) android projects and have found that almost none of them have comments or at least very few. Any idea why that is?
Mark M.
are they developed by teams or individuals? a lot of solo developers do not bother with comments
and in some cases, they write books that contain the comments :-)
9:25 AM
Kai H.
Sometimes individuals, often teams.
sudokai
My code has no comments either
Mark M.
my personal commenting approach is: comment the stuff that people might not understand, today or tomorrow
sudokai
:P
Mark M.
IOW, I try to aim for writing comments where I think there will be benefit, not writing comments for the sake of comments
Kai H.
So do I, but I still wondered.
As it makes it a bit hard to understand, at least for me.
Mark M.
for something with an API that I expected arbitrary people to consume, then I try to do a better job with JavaDocs/KDoc-style stuff
Kai H.
But with "normal" Android stuff you don't?
Mark M.
but, in the end, users don't run comments, managers don't (strictly) pay for comments, etc.
Kai H.
But another coder will read the comment.
Or rather won't if it's missing and go "huh???"
Mark M.
I wouldn't comment a findViewById() call, if that's what you mean
Kai H.
Neither would I. But a lot isn't as obvious imo.
sudokai
I don't comment, I make the code clear
Kai H.
For example if Navigation is used or not, where to find certain entry points, thoughts about the architecture and such.
sudokai: I am wondering if that is still possible with Kotlin and Jetpack
Mark M.
Kai: some of that should be documented, but code comments may not be the appropriate place
there might be a Wiki or other team documentation point that contains that sort of material
sudokai
Kai: I avoid language constructs that lead to poor readability
Mark M.
now, for an open source project, ideally that is all visible too, but it might not be, particularly for an open source project maintained by some firm
9:30 AM
Kai H.
sudokai: Right now that feels like 90 % of both Kotlin and Jetpack (currently "migrating" a very small app to kotlin and jetpack)
Mark M.
I'm sorry, but I need to wrap up today's chat
Kai H.
ideally :D
np
Thanks for your time
Mark M.
the next one is Saturday at 4pm US Eastern
have a pleasant day!
sudokai
Thanks
Kai H.
has left the room
sudokai
has left the room
Mark M.
turned off guest access

Tuesday, January 5

 

Office Hours

People in this transcript

  • Kai H.
  • Mark Murphy
  • sudokai