Office Hours — Today, April 24

Thursday, April 20

Apr 24
8:55 AM
Mark M.
has entered the room
Mark M.
turned on guest access
9:00 AM
wuqiang
has entered the room
Mark M.
hello, wuqiang!
how can I help you today?
wuqiang
long time no see
hello
Mark M.
do you have a question?
wuqiang
today i have a question
9:05 AM
ivano_ndrocchietto
has entered the room
Mark M.
wuqiang: please go ahead with your question
wuqiang
some app like kind of chat app needs start along with system,and do some initialization
Mark M.
(ivano: I will be with you shortly!)
wuqiang: I am sorry... was that your question?
wuqiang
i'm uploading a photo
Mark M.
it works much better if you copy and paste text
9:10 AM
Mark M.
so, it looks like you may be using my WakefulIntentService, since I see a doWakefulWork() method
wuqiang
yes
Mark M.
however, you appear to be doing asynchronous work, as you are registering a listener
wuqiang
it works ....
Mark M.
perhaps in testing, but it may not be reliable
once onHandleIntent() of an IntentService ends (or doWakefulWork() in this case), the service stops itself
wuqiang
so ,this is my question
Mark M.
your process can be terminated shortly afterwards
wuqiang
like this situation do u have another solution ?
Mark M.
if you want to do asynchronous work in a Service, use a regular Service, not IntentService or WakefulIntentService
when the asynchronous work is done, call stopSelf() to destroy the Service
9:15 AM
Mark M.
wuqiang: let me take a question from ivano, and I will return to you shortly to continue this discussion
ivano: your turn! do you have a question?
wuqiang
the part i'm embedded in you "doWakefulWork" need to work within whole my app
ivano_ndrocchietto
View paste
HI Mark,
I want to get rid of CursorLoaders+ContentProvider because recruiters want to see RXJava(and has some nice advantages, in terms of concurrency manangement and error handling)

I saw that JW quoted you on twitter for a project called cwac-loaderex, but is discontinued.

I guess today the way to go would be with RXJava2, do you know which way should I proceed? I guess the way to go would be using RXJava with Clean Code architecture. But cannot find on the internet any example of where should I put the content of  onCreateLoader and onLoadFinished in RXJAVA2
wuqiang
ok
Mark M.
"do you know which way should I proceed?" -- with respect to what?
I have not tried directly replacing loaders with RxJava
ivano_ndrocchietto
right. to meet the current best practice
Mark M.
I am far from expert on RxJava; I cannot tell you what the best practices are
ivano_ndrocchietto
if I well recall the CursorLoader API exploits an AsyncTask, that today is less desuete that populism
OK thank you anyway to consider my question
Mark M.
while I am not a fan of the Loader framework in general, there is nothing really wrong with CursorLoader itself AFAIK
I am skeptical that you can wrap RxJava in the Loader API, though I cannot rule that out
9:20 AM
Mark M.
so, I would approach this less as "how do I replace CursorLoader with RxJava" as "how do I implement RxJava", where your use case happens to be loading data
ivano_ndrocchietto
true. just need to stand to my future employee
Mark M.
I have a chapter on Rx basics in the book
ivano_ndrocchietto
I know
Mark M.
that material covers two of the three Loader features: asynchronous work and data retention across configuration changes
ivano_ndrocchietto
but querying a DB with a ThreadPool and RXJava is not trivial
what is the third then?
Mark M.
um, it should be
(other than the ThreadPool part, perhaps)
the third is the automatic delivery of fresh data
which can
which can't really be done other than for ContentProvider via ContentObserver
or for your own internal stuff via an event bus
ivano_ndrocchietto
Interesting building block to start to architecture
Mark M.
that feature is the one that breaks the Loader approach for most use cases
ivano_ndrocchietto
So ContentProvider is an Android Component that I have to maintain
Mark M.
only if you want to have one
ivano_ndrocchietto
after all is just a facade pattern
Mark M.
I use them for inter-process data exchange
purely within a process, they are more headache than they are worth IMHO
ivano_ndrocchietto
between apps or do you mean Client Server?
Mark M.
inter-process = between apps
ivano_ndrocchietto
I see thanks
Mark M.
with respect to database I/O, I expect that there are several libraries for reactive SQLite
whether in the form of an ORM or something lighter-weight
9:25 AM
Mark M.
let me switch back to wuqiang for a bit, and I will return to you later on
wuqiang: your turn! do you have another question?
wuqiang
in fact i need a almot totally same scheme to your GreenRobot3
Mark M.
well, greenrobot's EventBus is not mine, in that I did not write it
wuqiang
i mean your demo program
Mark M.
which one? I use greenrobot's EventBus in lots of sample apps
wuqiang
in chapter Evevt Bus Alternative
Mark M.
OK, so you are referring to the sample app where I use AlarmManager to raise events, delivering them to the UI via EventBus, or raising a Notification if the UI is not visible
9:30 AM
wuqiang
yes
selt start ,register a listener ,if there a Activity display the message,if there no Activity make a Notification
but it via a listener
I’m in your “doWakefulWork” register a listener for “wilddog” (it is totally compatible with FireBase)
Mark M.
again, a WakefulIntentService is not a good choice for this scenario
wuqiang
how could i do with my idea
the , what should i do ?
Mark M.
well, I doubt that you want to do that, as your users will be *very* upset with yo
er, upset with you
what you are proposing is that the user's device has to be powered on *all the time*
this will result in very short battery life
that is why in Android 6.0+, Google added Doze mode and app standby
wuqiang
it's so bad ...
ivano_ndrocchietto
( indeed)
Mark M.
those are there specifically because developers try doing things like this: having some service running all the time, keeping the device on, trying to do work
since you have indicated that you are using Firebase, switch to Firebase Cloud Messaging
use FCM to deliver chat updates to the devices
wuqiang
i can't use it , in china ....
Mark M.
then you cannot be using Firebase in general, AFAIK
9:35 AM
Mark M.
and you would need to work with Chinese device manufacturers to determine if there is some FCM replacement that you can use, that will work on the Xiaomi, Huawei, and similar devices
I assume that they have some solution to this problem
personally, I have largely given up on trying to update apps in the background
wuqiang
thanks so much
Mark M.
if you could somehow get away with occasional updates, you can use AlarmManager much as my sample app demonstrates
wuqiang
to check new message ?
Mark M.
where the WakefulIntentService grabs all available messages, but does not attempt to register a listener
this will not run very often once the device reaches Doze mode, though
for most types of apps, that might be acceptable
"chat", however, tends to imply real-time communications
wuqiang
yes
Mark M.
so long as the screen is on and your UI is in the foreground, if you wanted to try your Firebase listener approach, that may be fine
(I do not use Firebase and so I do not know if there are other efficiency issues with your approach)
but the listener approach will not work once the device gets to Doze mode
ivano_ndrocchietto
( Firebase does not give SQL query responses:( GRRR )
9:40 AM
wuqiang
so, let me search a FCM that could use in china
Mark M.
there are plenty of chat-style apps in China, so I assume that there is is some common pattern for how they are implemented
I just do not know the details
let me switch back to ivano...
ivano: your turn! do you have another question?
ivano_ndrocchietto
well yes regarding the submodules in Dagger
wuqiang
thins for you great suggestion
Mark M.
I have never used Dagger
ivano_ndrocchietto
I acnnot understand why I should use them in real life...
OK
did you maybe used so called seams to break up dependencies then?
Mark M.
I am sorry, but I do not understand that question
ivano_ndrocchietto
is a way to test code without using dagger
Mark M.
sure, by writing tests
where DI comes into play is if you have some huge code base, and you need to inject some replacement implementation of something in the middle of it for testing
I try not to have huge code bases
and I try not to need to inject some replacement implementation of something in the middle
my scenarios are different than those of many developers
9:45 AM
Mark M.
I don't have a problem with DI, but I'm not going to use it just for grins and giggles
I have not had a scenario where I needed it, so I have not used it
ivano_ndrocchietto
I see thanks
and sorry for the delay
I am at office:)
Mark M.
no problem
if either of you have any further questions, go ahead
wuqiang
no
thanks
9:50 AM
ivano_ndrocchietto
I have some issue with extensions functions in Kotlin
but I guess for the moment you are not doing any Kotlin being busy with Android SDK right?
Mark M.
correct, I have not played with Kotlin
ivano_ndrocchietto
is quite cool
coll guys say:)
OK no other questions
Ah
I know you do not manage architecture
but would like to know something between the relationship between interactors and presenters
but well is better if I dive personally on that
Mark M.
one problem with architecture discussions is that there is universal definition of terms
ivano_ndrocchietto
so true is so dialectic
Mark M.
for example, I have never heard the term "interactor" used before
9:55 AM
Mark M.
and while I have heard of "presenters", it is clear that their scope varies by who is talking about them :-)
10:00 AM
Mark M.
well, that is a wrap for today's chat
the transcript will be posted to https://commonsware.com/office-hours/ shortly
the next chat is tomorrow at 7:30pm US Eastern
have a pleasant day!
wuqiang
has left the room
ivano_ndrocchietto
has left the room
Mark M.
turned off guest access

Thursday, April 20

 

Office Hours

People in this transcript

  • ivano_ndrocchietto
  • Mark Murphy
  • wuqiang

Files in this transcript