Mark M. | has entered the room |
Mark M. | turned on guest access |
Sep 6 | 9:00 AM |
ndrocchietto_ivano | has entered the room |
ndrocchietto_ivano |
Hi Mark good american morning
|
Mark M. |
hello, Ivano!
|
Mark M. |
how can I help you today?
|
Sep 6 | 9:05 AM |
ndrocchietto_ivano |
first of all thank you for all your help in the last years, I will start to work as Android/Ios dev next month
|
Sep 6 | 9:05 AM |
Mark M. |
cool!
|
ndrocchietto_ivano |
thanks. secondly would like to ask you if you know an use case when I could use flatmap
|
ndrocchietto_ivano |
I understand really easy concatMap
|
ndrocchietto_ivano |
and even map
|
ndrocchietto_ivano |
but I cannot understand this operator flatmap
|
Mark M. |
you are referring to flatMap() on an RxJava Observable?
|
ndrocchietto_ivano |
actually I know that return an Observable that get flattened
|
ndrocchietto_ivano |
yes correct
|
ndrocchietto_ivano |
(actually you have been nonw a duck rubber for me because I get inspiration asking the questio, I could see the source code of flatmap() DOH!)
|
ndrocchietto_ivano |
I am going to check
|
Mark M. |
you use that when you have an Observable that needs to have some other Observable thing applied to it
|
ndrocchietto_ivano |
so basically when I need to make a transformation but need that returns an Observable?
|
ndrocchietto_ivano |
so map() does not return an Observable?
|
Mark M. |
no
|
ndrocchietto_ivano |
wow
|
ndrocchietto_ivano |
I get it
|
Mark M. | |
ndrocchietto_ivano |
so is before to apply a subscribe
|
Mark M. |
yes
|
Mark M. |
in the code that I linked to, I start with an Observable that may be doing disk I/O
|
Mark M. |
I then use a couple of map() operators to collect a piece of data from that, in the form of a generated passphrase
|
ndrocchietto_ivano |
but you should use map after flatmap
|
ndrocchietto_ivano |
because map() does not return an OBservable
|
Mark M. |
not necessarily
|
Sep 6 | 9:10 AM |
ndrocchietto_ivano |
in this logic I should use rather a Subject type
|
Mark M. |
in my case, I want to confirm that the passphrase is not already used in hacked data sources, so I flatMap() to pass the passphrase to another Observable that hits a Web service
|
Mark M. |
I use a Subject when I need the subscriber to have a consistent subscription, but the sources of data change
|
ndrocchietto_ivano |
I think I want to clone your repository this evening
|
ndrocchietto_ivano |
and play a bit
|
ndrocchietto_ivano |
so that I could in retrospective see if I am going to get a good understanding
|
ndrocchietto_ivano |
thank you very much
|
Mark M. |
that sample is covered in the chapter on repositories in "Android's Architecture Components"
|
ndrocchietto_ivano |
fantastic
|
ndrocchietto_ivano |
I started to read it
|
ndrocchietto_ivano |
although I am surprised in AAC you did not use a LiveData
|
Mark M. |
I have plenty of examples with LiveData
|
ndrocchietto_ivano |
but possibly is because you needed the more complex operators of RXJava2
|
ndrocchietto_ivano |
no doubt
|
Mark M. | |
Mark M. |
that sample in particular uses LiveData
|
Mark M. |
my general approach is to use RxJava for "back end" things (repositories) and use LiveData in the UI area
|
Mark M. |
using things like LiveDataReactiveStreams to map between them
|
ndrocchietto_ivano |
fantastic idea
|
Mark M. |
LiveData is not very powerful, but it is excellent for the UI, given that it is aware of the lifecycle
|
ndrocchietto_ivano |
so that you can easily couple it with ViewModel in UI, while doing all the heavy backend API lifts with RXJava
|
Mark M. |
precisely
|
ndrocchietto_ivano |
really glad I can focus my life from now on coding
|
ndrocchietto_ivano |
have a pleasant day
|
ndrocchietto_ivano |
and thank you very much
|
Sep 6 | 9:15 AM |
Mark M. |
you're weclome!
|
Mark M. |
er, welcome!
|
ndrocchietto_ivano |
:)
|
Sep 6 | 9:35 AM |
Hazi c. | has entered the room |
Mark M. |
hello, Hazi!
|
Mark M. |
how can I help you today?
|
Hazi c. |
Hi
|
Sep 6 | 9:40 AM |
Mark M. |
do you have an Android app development question?
|
Hazi c. |
yes one minute let me explain it
|
Hazi c. |
View paste
|
Sep 6 | 9:45 AM |
Mark M. |
I have not seen any successful implementations of what you describe, because it winds up being fragile. What happens to App B if App A is not installed? What happens to App B if App A is installed, used, then uninstalled?
|
Mark M. |
but in terms of secure IPC, a bound service is probably the best, though any IPC in theory should be secure
|
ndrocchietto_ivano |
(why not a PendingIntent?)
|
Mark M. |
Ivano: because a PendingIntent is not IPC; it enables IPC
|
ndrocchietto_ivano |
(ok thanks)
|
Mark M. |
Hazi: you cannot rely on App B being able to access this token from anywhere outside of App B, as there may not *be* anything outside of App B
|
Hazi c. |
Do you know if it is possible to send data directly between two apps without saving them to some local DB first? (as in SP/SQL/etc)
|
Mark M. |
sure -- use IPC
|
Hazi c. |
I have tried an IPC implementation using AIDL, but had to save the data locally
|
Mark M. |
pass the token as a String in an AIDL method parameter
|
Mark M. |
or, if the token cannot be represented as a String, pass it as a byte[]
|
Mark M. |
if the token is massive (100+KB), ask yourself why the token is so big
|
Sep 6 | 9:50 AM |
Hazi c. |
It can be passed as String. A developer in my team tried to look into the AIDL solution, or IPC in general, he could not find a way to share data between processes without saving the data locally
|
Hazi c. |
Is there any source or link you can refer me to?
|
Mark M. |
I have a chapter in "The Busy Coder's Guide on Android Development" that covers remote services with AIDL
|
Mark M. |
it has a few sample apps
|
Mark M. |
they involve passing strings around, and they do not persist those strings to local storage
|
Mark M. |
View paste
|
Mark M. |
App A binds to the service from App B and calls hereIsTheToken() on its AppBService proxy
|
Mark M. |
App B gets the token in its AppBService.Stub subclass implementation of hereIsTheToken()
|
Mark M. |
no local storage required
|
Hazi c. |
Alright, great, this is really useful and seems to be exactly what we were looking to achieve
|
Hazi c. |
I have one more question please, if possible
|
Mark M. |
go right ahead
|
Mark M. |
(Ivano, if you have another question, chime in)
|
Sep 6 | 9:55 AM |
Hazi c. |
Lets say I have a View (CardView for my current example). In some cases, by some business logic, I am changing the CardView's background. At end of everything, I want to restore the CardView's background to the default one it started with (usually depends on the API/Style/Theme the app is using)
|
Hazi c. |
So the quesiton would be, how could I restore that CardView background? Can I load it using a style? Is there any method to create a background Drawable from a style in runtime?
|
Hazi c. |
Or perhaps there is a much easier solution I wasn't aware of
|
Mark M. |
what I would try is calling getBackground() on the View, holding onto that Drawable, and later calling setBackgroundDrawable() to restore it
|
Hazi c. |
So we did that as a temporary solution and decided to ask you :)
|
ndrocchietto_ivano |
(no questions mark, thanks)
|
Mark M. |
did you run into a problem with that approach?
|
Hazi c. |
No, but it made me wonder if there is indeed a way to restore a view's default background at any point?
|
Hazi c. |
Just decided to ask out of curiousity
|
Mark M. |
I cannot think of a good way to do that, other than to re-inflate the layout resource
|
ndrocchietto_ivano |
(extract a method and make it static in an utility class with a view)
|
Mark M. |
I'd hold onto the Drawable in the ViewHolder or something for this CardView, if there is one
|
ndrocchietto_ivano |
(nice)
|
Sep 6 | 10:00 AM |
Mark M. |
otherwise, you might use getTag()/setTag(), though I haven't used those in years
|
Hazi c. |
Yes, we're simply holding on to the default background until we need to apply it again
|
Mark M. |
that's a wrap for today's chat
|
Hazi c. |
Okay Mark, thank you for your time... That would be all for now
|
ndrocchietto_ivano |
thanks
|
Mark M. |
I will post the transcript to https://commonsware.com/office-hours/ shortly
|
Hazi c. |
Much appreciate, have a good day
|
Mark M. |
you too!
|
Mark M. |
the next chat is Saturday at 4pm US Eastern
|
ndrocchietto_ivano | has left the room |
Hazi c. | has left the room |
Mark M. | turned off guest access |