Office Hours — Today, October 3

Thursday, October 1

Mark M.
has entered the room
Mark M.
turned on guest access
Oct 3
4:00 PM
Derek
has entered the room
Mark M.
hello, Derek!
how can I help you today?
Derek
Hi Mark
I have a question regarding app widgets
Mark M.
OK, I can probably help with that
Derek
the onEnabled method of an app widget gets called the first time a user adds the widget to the home screen. Another way it is called is if the device reboots with the widget already on home screen.
My question is whether can I distinguish between how the onEnabled method is called?
4:05 PM
Mark M.
I doubt it
Derek
so if the onEnabled method is called on device reboot (instead of user interaction), I want it to be handled differently
Mark M.
you could keep track of whether you have ever been enabled before (e.g., SharedPreferences)
on the first onEnabled() call, that will be false, so you do whatever logic you need for being added to the screen
(in addition to setting the preference to true)
later onEnabled() calls would see a value of true, so you do whatever logic you need for reboots or other major launcher changes
Derek
okay, I think this is an idea I can integrate into my application.
thank you for your time
Mark M.
happy to help!
Derek
has left the room
4:15 PM
trocchietto
has entered the room
Mark M.
hello, trocchietto!
how can I help you today?
4:20 PM
trocchietto
ciao Mark, ik zou graag weten iets over RXJava en LiveData
ops sorry
I spoke too much Dutch today
I want to ask you something about RXJava in combination with LiveData
Mark M.
OK, I can probably help with that
trocchietto
namely my team usesrxjava everywhere
trocchietto
has left the room
trocchietto
has entered the room
trocchietto
has left the room
trocchietto
has entered the room
trocchietto
sorry
Mark M.
no problem!
trocchietto
namely in short I have the feeling that all the error we get due to IllegalStateException are due to the fact that we should use LiveData to wrap Observable and. Single from RXJava
Mark M.
what is triggering the IllegalStateExceptions?
4:25 PM
trocchietto
onSavedInstance
is a well known old school issue
Mark M.
I would be surprised if onSaveInstanceState() is somehow affected by a choice of reactive frameworks, though
trocchietto
yes is the combination
rxjava was not tough to manage the SDK from Android
causing every kind of side effects if used in the wrong way
but the point is:
do you think that wrapping Rxjava inside Live data could be a way
to prevent this kind of errors
I guess live data viewModel is a solid construction Android engineer use to prevent some issues
Mark M.
well, again, I do not really understand how onSaveInstanceState() is affected by your use of RxJava
trocchietto
oh is something caused by startActivity for result
when go back to the previous activity fragment often crashes
our crashlytics has often this kind of issue
Mark M.
¯\_(ツ)_/¯
I typically use LiveData for delivering updates to activities and fragments, for viewstates to be rendered to views
where RxJava handles everything else, from the viewmodel on back
4:30 PM
Mark M.
sometimes, though, I will expose RxJava from a viewmodel, such as for events, since LiveData does not model events well
trocchietto
is this issue IllegalStateException cannot perform this action after onSaveInstanceState
there are numerous blog that describe this lifecycle issue
because activity already saved UI state and could be destroyed
Mark M.
that feels like you are doing navigation at inopportune times
trocchietto
mmh
I use Anko
Mark M.
I have never used Anko, so I know very little about it
trocchietto
that has these sugar explicit intents
and furthermore is deprecated
and then we use on top of everything rxjava
I have the feeling android is built on layers
Mark M.
a layered architecture is typical in modern Android app development, if that is what you mean
trocchietto
no
I do not speak about uncle bob thing
I say that Android imo junior opinion is built as pompei
4:35 PM
trocchietto
from palm os idea as broadcast, to java xml and old school patterns, adding above fragments, then one uses also not official libraries as dagger and rxjava and boom crashes everything
Mark M.
again, ¯\_(ツ)_/¯
Daniel P.
has entered the room
Mark M.
if using Dagger and RxJava always crashed apps, nobody would be using those libraries, because they would have a terrible reputation
trocchietto
true
Mark M.
(hello, Daniel -- I will be with you shortly!)
trocchietto
please take care of Daniel is fine with me
Mark M.
OK
Daniel: hi! how can I help you today?
Daniel P.
I think I'm ok at the moment, just re-subscribed and saw there were office hours and figured I'd check it out
Mark M.
thanks for renewing!
Daniel P.
I may ask about testing or something shortly but right now I'm just reading. Appreciate your resources.
Mark M.
glad you like them!
but, yes, these chats are mostly for getting answers to your specific questions
in any case, if either of you have a question, go right ahead!
4:40 PM
Daniel P.
Have you any resources on Jetpack compose at the moment?
Mark M.
in terms of books, no
I run a Compose newsletter: https://jetc.dev/
Daniel P.
That's great actually, thank you
Mark M.
I hope to write more about Compose in the coming months
the dev releases were *really* fluid in terms of APIs, so I eventually got fed up and decided to wait until the alphas started shipping
so, with luck, I'll have something in early 2021
Daniel P.
I was gonna say, I figured I'd start learning once the API was stable, I hope alpha has been more stable than the dev preview thus far
Mark M.
there hasn't been nearly as many big API changes
Daniel P.
I'll get out of here. Thanks for providing this. You two have a good day
Mark M.
you too!
Daniel P.
Thanks for that by the way, I'll give it a look son
4:45 PM
trocchietto
have a nice week end Daniel
So is not a good practice, dear Mark, to wrap RXJava inside LiveData
Mark M.
I am not certain what you mean by "wrap"
trocchietto
you would rather use them separately in the same app
Mark M.
and, I am not certain what you mean by "separately" :-)
trocchietto
well use case 1
namely : Expose your Rx Observable from the repository, and subscribe() to it in the ViewModel. In the subscriber's onNext(), use setValue() to wrap your viewstate object in a MutableLiveData, and expose that as a non-mutable LiveData to the UI. Manually dispose the subscription in onCleared().
Mark M.
that's pretty much what I've done on the projects that I have been helping on for the past couple of years
trocchietto
so this is a wrap right?
you have the Observable kinda inside LiveData
so LiveData is the superhero start that speaks with ViewModel
and take care that the lifecycle and the reactive magic works as a charm
and BTW do you have in your repository something as RXJAva with Live Data I can pull
Mark M.
I would not use "wrap" as the verb for that pattern, but otherwise, I have had reasonable luck with the pattern
trocchietto
?
4:50 PM
trocchietto
I see
Mark M.
I have not written about RxJava in the second-generation books
trocchietto
is a pattern Like, I learnt from a really opinionated GDE, never do strange thing
Mark M.
I have some RxJava samples in *The Busy Coder's Guide to Android Development*, but that is getting a bit old
so I do not have a public repository to point you towards that demonstrates the pattern that we are discussing
trocchietto
yeah that is the problem with development, but should be fine I am a fun of SICP in Lisp
Mark M.
long term, I hope that coroutines can replace all of this
trocchietto
well thank you anyway, you gave me a reasonable tunnel light exit
Mark M.
you're welcome!
trocchietto
as I told you some other sat ago I am going into the magnificent world of pseudo declarative reactive flutter
Mark M.
OK -- I won't be able to help you with Flutter, other than at a theoretical level
trocchietto
in December google should release a plugin official that can be officially interoperable with existing android native apps
I know but android is far to go away
and a good flutter dev have to know android and objective c to write plugins
I praise god for the complexity of Android that makes every other ecosystem easy to catch
4:55 PM
trocchietto
btw my senior does not want to migrate to coroutines :(
hope they will make rxjava deprecated
Mark M.
well, migrating to coroutines *is* a fair bit of work
and since RxJava 3 is out, it is not going away any time soon
trocchietto
zucht!
you know I hate the idea that OO paradigm should become kinda functional/reactive
focus in the k in life, I am turning almost fifty and I learned that
use scala if you want a functional feeling
mixing things is really not good imo
coroutines are really cool
Mark M.
they definitely have their advantages
trocchietto
and match OO sequence, selection, iteration
because make concurrency sequential
where I have all these rxjava publisher and Jake Wharton behaviour relay that make the poor Dijkstra crazy from the other world
5:00 PM
trocchietto
is like we are coming back to the games you were programming in the eighties with GOTO
Daniel P.
has left the room
Mark M.
OK, that's a wrap for today's chat
the next one is Tuesday at 8:30am US Eastern
have a pleasant evening!
trocchietto
have a nice day
thanks
trocchietto
has left the room
Mark M.
turned off guest access

Thursday, October 1

 

Office Hours

People in this transcript

  • Daniel Perez
  • Derek
  • Mark Murphy
  • trocchietto