Office Hours — Today, December 4

Saturday, December 1

Mark M.
has entered the room
Mark M.
turned on guest access
Dec 4
9:00 AM
Urban
has entered the room
Mark M.
hello, Urban~
er, Urban!
Urban
Hey Mark.
Mark M.
how can I help you today?
Urban
Can I proceed with a question?
Mark M.
go right ahead!
Urban
Before I do, I would just like to thank you for amazing books! Really inspiring
Mark M.
thanks for the kind words!
Urban
SO, my first question is regarding View loading. So basically at configuration change, you can get nullpointer if the view that you are reffering to has not been loaded
9:05 AM
Urban
One of the soultion for it that I have been using is PostDelayed and you delay it for some time
however, this is clearly not the optimal solution as for some it might be 50ms and for some 500ms
So, my question is if there is any option to run a function AFTER the view has been loaded?
Mark M.
you are the one who is causing the Views to be created: setContentView(), onCreateView(), etc.
so, you know when they are ready, in general
there are odd cases, such as Google Maps, but usually you know when your views are ready
Urban
So basically, if I call this function after I create a view it should not throw NullPointer?
Mark M.
generally, yes
and if it does, you need to ask yourself why that view is not ready when you think that it shoudl be
er, should be
Urban
thanks. But are there still any functions to delay the run of a funciton anyway (such as PostDelayed) but would acctually wait for completion of something?
Mark M.
it depends on the "something" :-)
for example, in the case of Google Maps, there are things that you cannot do until the map is fully laid out
such as move the camera
9:10 AM
Mark M.
for that, you can use things like addOnLayoutChangeListener()
Urban
So if I understand you correctly, there is really not point of delaying stuff if you "know" what you are doing nad what are the processes?
and*
Mark M.
yes
of course, this can get tricky with third-party libraries that do not behave well, such as the Google Maps case
so I reserve the post()/postDelayed() stuff for cases where a library is not well-behaved and I need *something* to get the code to work
I also sometimes use it as a proof-of-concept, to confirm that my issue is "a timing thing", then try to find some cleaner fix to the real problem
Urban
but what time should one give in postDelayed if you decide for it? Seems pretty much a gamble to me
Mark M.
oh, absolutely
frequently, I find that post() is sufficient, as you just need to get your work onto the end of the event queue
if postDelayed() is needed... it's largely guesswork, based in part on your test devices and how you think they compare speed-wise to your users' devices
9:15 AM
Urban
I have also stumbled upon "Idle Handler" class instead of "postDelayed()". Does it has any value?
Mark M.
I have not used it personally
Urban
Well, first of all thanks for your answer to my first question(s).
Mark M.
you are welcome!
Urban
Now to the second one if that is okay :)
Mark M.
sure -- nobody else is here, so go right ahead!
Urban
is it usually that empty btw?
it seems that you are very popular guy to get with contact
in contact with*
Mark M.
frequently, there is only one person here
there used to be more, back when I had more subscribers
Urban
Oh, okay
SO, the second thing that I found problematic in my app was the popupWindow. I wanted to prevent its dismissal with .setFocusable(false) which worked up to a some point. However, no matter how I was abusing the .setFocusable(), it still wouldnt work
The idea I had for fixing this was to use TouchInterceptor and catching touch events outisde
9:20 AM
Urban
However, I would still like to keep my menu buttons on Action Mode clickable
But after trying several MotionEvent. combinations, I did not manage to find an click interceptor for a menu
Mark M.
why are you using a PopupWindow, rather than just views in your activity/fragment?
Urban
What do you mean with views? I have a popupwindow populated with ListView that has an Adapter, ...
Mark M.
I just do not see many people using PopupWindow versus either views in the activity/fragment or some form of Dialog, that's all
Urban
I found it preatty neat, that is all ;P
Dont really have a specific reason
Mark M.
OK
Urban
Fits into the app nicely
And it also works fine BUT the issue with dismissal
Mark M.
outside of a few samples (e.g., pre-O mouse-based context menus), I have not used PopupWindow or its variants very much
Urban
After long click on one of the items, it display actionMode whereas I would like buttons to be clickable at the start and not the click dissmiss the popupwindow first
oh okay, no worries
was just wondering if you perhaps knew how should I fix it
9:25 AM
Mark M.
nothing comes to mind, sorry
Urban
No problem :)
Can I also ask you some of more general questions on Android developing while we are alone here?
Mark M.
go right ahead!
Urban
So basically, I am writing an app that would use internet online base (of my own) to give some data back to the user. For this, I was thinking I should use mySQL with PHP interceptor with Retrofit call. However, I have recently found that there is also a Firebase DB and several others. Is my thinking of doing this okay or is it slightly outdated principle of doing this?
Mark M.
it is a question of control
personally, I will not use Firebase services, as I would rather either retain control (using my servers) or give business to smaller competitors
so, in terms of running your own server, if you feel comfortable in doing that, there is nothing wrong with that approach
9:30 AM
Urban
Would you reccomend anything better or does this seem sufficient enough?
Mark M.
well, I'm not a PHP guy, so I wouldn't be using that :-)
but PHP is fairly popular, so you should have lots of support for it
Urban
So, if that is not a secret, can you outline how would YOU achieve the same functionality that I have described?
Mark M.
well, for the new Warescription site, I used Kotlin and SQLite
SQLite because I don't have a particularly large database
Kotlin because I wanted to explore Kotlin in a non-Android setting
the previous Warescription site was Ruby and SQLite
Urban
But up to my knowledge, SQLite is a single-device based database whereas I would require an online one. Can it be extended to online access?
Mark M.
unless you have a server farm or database cluster, your MySQL is a single-device based database
you are wrapping it in a Web service (I think) implemented in PHP
in my case, I wrapped SQLite in a Web service written in Ruby, then in Kotlin
(though actually mine is a plain Web site, not a Web service, except for a few things for payment processors)
9:35 AM
Mark M.
PHP is typically used with MySQL, and so that is probably the simplest database to use if you are going to go with PHP for the Web stuff
in principle, you could use PHP with whatever other database that PHP supports
Urban
Oh, so there is not that big of a difference between them... I thought I would gather all data on mySQL and than perform quiries and save data on personal SQLite
Mark M.
SQLite can be used on clients or servers
MySQL is not really designed for use on clients
your approach is perfectly fine, but there is no strict requirement to use MySQL on a server
for example, lots of businesses use Oracle
I happen to use SQLite
Urban
Thank you for that insight!
And (hopefully) last thing: I have gone through your book on Data Binding/JavaRx/MVVM...
And they seem very nice principles to master. However, they are sort-of-a intimidating for a "beginner" Android developer to use
I have tried using them in my app but it does go rather slowly
That being said, would you suggest me trying to master those principles or would you say that they are not worth losing time on=
9:40 AM
Mark M.
what is your objective for Android development? for example, is the app that you are building just for personal enjoyment, or are you looking for it to be something that you show to prospective employers?
Urban
Both. I am planning to spend few months on it and than publish it
(If I manage to come that far)
I have written lets say half of it already using those principles as much as possible
But they do take a long time. SO my question would be if they are worth losing time on
Mark M.
for the benefit of employers, I would recommend that you demonstrate some experience with current development techniques, notably reactive programming and some structured GUI architecture
whether the reactive programming is RxJava, LiveData, RxJava+LiveData, Kotlin coroutines, or something else, is really up to you
similarly, whether your GUI architecture is MVC, MVP, MVVM, MVI, or something else, is really up to you
and if you were not going to be using the code as "proof of ability", you would be welcome to skip all of that, if you feel that you can deliver a quality app to your users in other ways
Urban
So, you are low-key urging me to go with these principles, correct? :-)
Mark M.
given your objectives, yes
9:45 AM
Mark M.
but, that is why I asked about your objectives -- if the app was for personal education and nothing more, you're welcome to do what you want
employers are going to be less interested in the specifics of what your app does as much as how quickly you are likely to "come up to speed" on how *they* build apps
and the current trends are strongly towards reactive programming, formal GUI architectures, and Kotlin
the more you can demonstrate those things, the more useful your app will be in terms of employment
Urban
That is true. I should probably focus more on mastering these and less time complaining about the time I spend doing so ;P
And one veeeeeery last thing: I intended to use Firebase Cloud Messaging as a part of detecting mySQL changes to confer notifications + data changes to users. Would you say that using FCM is okay for that purpose or you have a better sugestion?
Mark M.
if you need real time asynchronous delivery of updates, FCM is "the only game in town", for better or worse
if you do not need it to be real time, and you want to use JobScheduler or WorkManager to periodically poll your server (e.g., every few hours), that's fine too
Urban
I like your "only game in town" comparison
Mark M.
I wish that we had more competition in the real-time push messaging space, but, then again, I wish that we had more competition with lots of things in Android
Urban
Are there any Android aspects (apart from ones we discussed) that you suggest for a "beginner" Android developer to learn?
9:50 AM
Mark M.
fragments and configuration changes are important
Urban
Perhaps slightly less beginner ;P
"Intermediate" is perhaps a better put
Mark M.
well, after that and architectural concerns, it starts to either get into specifics based on app type (media players versus productivity apps versus games) or into "professional polish" (e.g., crash logging, performance analysis)
so once we get past the really beginner things, it is difficult to give blanket recommendations
Urban
Oh, okay.
Is it worth learning the Testing with Unit etc.=
Mark M.
yes
you may not need to get too fancy with it (e.g., Robolectric)
Urban
Which is the one testing method/program you would recommend me to learn?
If you can give one that is
Mark M.
having unit tests for things that do not depend on Android, and having instrumented tests for the things that *do* depend on Android, would be a good "proof of ability" for employers
9:55 AM
Mark M.
in terms of particular technologies, Espresso and Mockito would be useful
Urban
And are these of much value in Android debugging processes?
Mark M.
I am not completely certain what you mean by "Android debugging processes"
tests are useful for detecting where you make mistakes with changes to code in the future
Urban
I was asking if these tests are more for complex scenarios or also "more basic" ones
But you have already replied on that one with the above
Mark M.
I view tests mostly as making sure that "future you" does not screw up what "current you" did
Urban
Haha well said :-)
All in all, I am very grateful that you had this discussion with me
I have learned A LOT
Mark M.
I am happy to help!
Urban
And hopefully this help me to become a better Android developer
Have a nice day :)
Mark M.
BTW, the transcript for this will be posted to https://commonsware.com/office-hours/ shortly after the chat ends
Urban
okay, thank you
Enjoy the rest of the day!
Mark M.
you too!
10:00 AM
Urban
has left the room
Mark M.
turned off guest access

Saturday, December 1

 

Office Hours

People in this transcript

  • Mark Murphy
  • Urban