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!
|
Mark M. |
how can I help you today?
|
Derek |
Hi Mark
|
Derek |
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.
|
Derek |
My question is whether can I distinguish between how the onEnabled method is called?
|
Oct 3 | 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)
|
Mark M. |
on the first onEnabled() call, that will be false, so you do whatever logic you need for being added to the screen
|
Mark M. |
(in addition to setting the preference to true)
|
Mark M. |
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.
|
Derek |
thank you for your time
|
Mark M. |
happy to help!
|
Derek | has left the room |
Oct 3 | 4:15 PM |
trocchietto | has entered the room |
Mark M. |
hello, trocchietto!
|
Mark M. |
how can I help you today?
|
Oct 3 | 4:20 PM |
trocchietto |
ciao Mark, ik zou graag weten iets over RXJava en LiveData
|
trocchietto |
ops sorry
|
trocchietto |
I spoke too much Dutch today
|
trocchietto |
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?
|
Oct 3 | 4:25 PM |
trocchietto |
onSavedInstance
|
trocchietto |
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
|
trocchietto |
rxjava was not tough to manage the SDK from Android
|
trocchietto |
causing every kind of side effects if used in the wrong way
|
trocchietto |
but the point is:
|
trocchietto |
do you think that wrapping Rxjava inside Live data could be a way
|
trocchietto |
to prevent this kind of errors
|
trocchietto |
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
|
trocchietto |
when go back to the previous activity fragment often crashes
|
trocchietto |
our crashlytics has often this kind of issue
|
Mark M. |
¯\_(ツ)_/¯
|
Mark M. |
I typically use LiveData for delivering updates to activities and fragments, for viewstates to be rendered to views
|
Mark M. |
where RxJava handles everything else, from the viewmodel on back
|
Oct 3 | 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
|
trocchietto |
there are numerous blog that describe this lifecycle issue
|
trocchietto |
because activity already saved UI state and could be destroyed
|
Mark M. |
that feels like you are doing navigation at inopportune times
|
trocchietto |
mmh
|
trocchietto |
I use Anko
|
Mark M. |
I have never used Anko, so I know very little about it
|
trocchietto |
that has these sugar explicit intents
|
trocchietto |
and furthermore is deprecated
|
trocchietto |
and then we use on top of everything rxjava
|
trocchietto |
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
|
trocchietto |
I do not speak about uncle bob thing
|
trocchietto |
I say that Android imo junior opinion is built as pompei
|
Oct 3 | 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
|
Mark M. |
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!
|
Mark M. |
but, yes, these chats are mostly for getting answers to your specific questions
|
Mark M. |
in any case, if either of you have a question, go right ahead!
|
Oct 3 | 4:40 PM |
Daniel P. |
Have you any resources on Jetpack compose at the moment?
|
Mark M. |
in terms of books, no
|
Mark M. |
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
|
Mark M. |
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
|
Mark M. |
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
|
Oct 3 | 4:45 PM |
trocchietto |
have a nice week end Daniel
|
trocchietto |
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
|
trocchietto | |
trocchietto |
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?
|
trocchietto |
you have the Observable kinda inside LiveData
|
trocchietto |
so LiveData is the superhero start that speaks with ViewModel
|
trocchietto |
and take care that the lifecycle and the reactive magic works as a charm
|
trocchietto |
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 |
?
|
Oct 3 | 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
|
Mark M. |
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
|
trocchietto |
I know but android is far to go away
|
trocchietto |
and a good flutter dev have to know android and objective c to write plugins
|
trocchietto |
I praise god for the complexity of Android that makes every other ecosystem easy to catch
|
Oct 3 | 4:55 PM |
trocchietto |
btw my senior does not want to migrate to coroutines :(
|
trocchietto |
hope they will make rxjava deprecated
|
Mark M. |
well, migrating to coroutines *is* a fair bit of work
|
Mark M. |
and since RxJava 3 is out, it is not going away any time soon
|
trocchietto |
zucht!
|
trocchietto |
you know I hate the idea that OO paradigm should become kinda functional/reactive
|
trocchietto |
focus in the k in life, I am turning almost fifty and I learned that
|
trocchietto |
use scala if you want a functional feeling
|
trocchietto |
mixing things is really not good imo
|
trocchietto |
coroutines are really cool
|
Mark M. |
they definitely have their advantages
|
trocchietto |
and match OO sequence, selection, iteration
|
trocchietto |
because make concurrency sequential
|
trocchietto |
where I have all these rxjava publisher and Jake Wharton behaviour relay that make the poor Dijkstra crazy from the other world
|
Oct 3 | 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
|
Mark M. |
the next one is Tuesday at 8:30am US Eastern
|
Mark M. |
have a pleasant evening!
|
trocchietto |
have a nice day
|
trocchietto |
thanks
|
trocchietto | has left the room |
Mark M. | turned off guest access |