Office Hours — Today, April 27

Saturday, April 24

Mark M.
has entered the room
Mark M.
turned on guest access
Jan
has entered the room
Mark M.
hello, Jan!
how can I help you today?
Jan
Hi, Mark, Do you know anything about Network Service Discovery? About 90% of the time I get no discovery at all using it. I'm not trying to do any registration of service - just discovery and resolution.
Mark M.
I happen to be using it for a project for my primary client right now
it is fairly frustrating, though I have a higher success rate than 10%
are you using NsdManager?
Jan
Yes I use NsdManager.
Apr 27
7:30 PM
Mark M.
one problem with NSD is that it relies on multicast, and so you may run into problems purely based on the network
some home WiFi routers refuse to route multicast packets, for example
Jan
onDiscoveryStarted gets started but then nothing else every gets called. No onServiceFound. I tried it on Apple phone and discovery worked great. I tried to break it and couldn't. So I don't think it's global to my router/network.
Mark M.
I agree, that sounds more specific to Android
Jan
Sometimes it'll work but no pattern to that. So it worked twice in about 50 attempts today. One thing I noticed is that sometimes it thinks the discovery listener is still active when the app crashed. But I was using a single in Koin for it and changing that to factory hopefully won't have that problem any more.
7:35 PM
Mark M.
yeah, NsdManager is very fussy when it comes to having multiple discovery passes going at once
Jan
Is there any third party I could try? I downloaded several from github and from play store. They didn't work either. So maybe it is my phone specifically.
Mark M.
we used to use a third-party library, and I eventually tossed it out and wrote something direct to NsdManager
Jan
Okay. That's my only topic for today. Thanks.
Mark M.
sorry I didn't have a better answer for you!
7:40 PM
ndrocchietto i.
has entered the room
7:45 PM
Mark M.
hello, Ivano!
Jan: if you come up with another question, let me know!
ndrocchietto i.
hello Mark
Mark M.
Ivano: your turn! how can I help you today?
ndrocchietto i.
well i do not get if foreground services should be used instead od working manager.the official guide say kinda not
Mark M.
(Jan: BTW, https://play.google.com/store/apps/details?id=c... finds the NSD advertised items on my network)
Ivano: WorkManager is good for short one-off jobs or periodic work
a foreground service is for continuous background operation
ndrocchietto i.
yes deferred
Mark M.
so, for example, a music player would use a foreground service, not WorkManager
ndrocchietto i.
but you do not run in issues with android modern numbers?
Mark M.
with a foreground service? not really, though there are some limitations on starting one from the background in Android 12 IIRC
ndrocchietto i.
ok
i am gonna study more and will come back to you
Mark M.
but I have not seen issues with a foreground service launched from the foreground, such as from user interaction with an activity
ndrocchietto i.
thanks i go to sleep will come back. sorry for all the questions in the last period.changing job and
7:50 PM
ndrocchietto i.
want to learn a lot
Jan
has left the room
Mark M.
I am happy to try to help!
ndrocchietto i.
well jan left
would like to ask you what happen if somebody does a call while i am getting a retrofit call or something similar,
Mark M.
"does a call" meaning a voice call?
ndrocchietto i.
coroutines and rxjava are not going to help
yes
should i use services for all the use cases then?
Mark M.
if you are worried about losing your network connection, that is not a problem on GSM networks
oh, are you worried about your app moving to the background while the call is in progress?
ndrocchietto i.
yesss
Mark M.
ah
ndrocchietto i.
really worried
Mark M.
the big variable is how long you are trying to do network I/O while in the background
ndrocchietto i.
in theory i should put everything i do under a service?
Mark M.
probably not, but it would depend a lot on your app and what you are trying to do
ndrocchietto i.
ok
and last thing
please
i saw a tutorial using lifecycleservice
7:55 PM
ndrocchietto i.
and i saw that also workmanagers can be combined with lifecycle
via live data
so my question is if i use flow and get ridd of livedata, to be sure are bbound to the cycle, should i take care of coroutine scope?
Mark M.
for activities and fragments, usually you should use a CoroutineScope tied to a lifecycle, or tied to the ViewModel (viewModelScope)
ndrocchietto i.
yess
great
was expecting this
ah one other small nouance, i am mastering coroutines but really do not get why the scope can be declared with a plus sign in an instance variable. cannot find sounding explanations Mark
8:00 PM
Mark M.
there is a plus() function available for CoroutineScope
plus() is an operator function
ndrocchietto i.
inmean +
Mark M.
when you see 1 + 2, the compiler converts that to 1.plus(2)
ndrocchietto i.
i mean +
Mark M.
so, anything that has a plus() function implementation can be used with the + operator
ndrocchietto i.
no i do not mean that
Mark M.
do you have an example?
ndrocchietto i.
please let me tempt your patience finding an example
looking for
i have it but have to log
View paste
private val coroutineScope = CoroutineScope(Dispatchers.Main + parentJob)
8:05 PM
ndrocchietto i.
this plus
Mark M.
it's the same thing, in the end
Dispatchers.Main is a CoroutineContext
CoroutineContext has a plus() function
so, what you have is equivalent to: private val coroutineScope = CoroutineScope(Dispatchers.Main.plus(parentJob))
ndrocchietto i.
and why i need to add this parentjob
really do not get
what is wrong with withContext(Main)
Mark M.
it is simply a convenience syntax for combining two CoroutineContext objects
nothing
ndrocchietto i.
mmh
Mark M.
it does not specify the parent job, for structured concurrency, but you do not always need that
ndrocchietto i.
i have an idea tomorrow will try to run without parent job
Mark M.
and I think withContext() looks up the parent job automatically, but my memory is fuzzy on the details
ndrocchietto i.
ok is kind of boiler plate i guess, in modern code i do not see, only in tutorials
thank you
Mark M.
yes, I rarely see that syntax
ndrocchietto i.
thank you
really helpful
8:10 PM
ndrocchietto i.
have a nice evening
Mark M.
you too!
get some sleep! :-)
ndrocchietto i.
thanks yes really need, i am dreaming code unfortunately in this period
bye
8:30 PM
ndrocchietto i.
has left the room
Mark M.
turned off guest access

Saturday, April 24

 

Office Hours

People in this transcript

  • Jan
  • Mark Murphy
  • ndrocchietto ivano