Office Hours — Today, March 9

Monday, March 6

Mar 9
7:20 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:25 PM
Paul R.
has entered the room
Mark M.
hello, Paul!
how can I help you today?
Paul R.
Greetings. Ready for another epic?
View paste (10 more lines)
Here goes:  Next topic: Notifications

I am now aware of three options for handling device notifications for an app:

1) A separate server to register devices, do the notification processing and send FCM messages to devices.  For a number of reasons I do not like this approach.
2) Use the just introduced Beta Firebase Cloud Functions, which are a variant on #1 and only just announced.  I'm inclined to take a wait-and-see approach here.
3) Us an app background Service that wakes up periodically (every few minutes or so) and processes data for a fraction of a second or a small number of seconds leaving breadcrumbs on the database for the next check cycle.  This seems like a reasonable approach but has battery mis-use risks.

AlarmManager or JobScheduler look like the best choices for 3).  Firebase JobDispatcher (a GitHub library) is another choice that uses the JobScheduler interface but works back to API level 9.

My questions are about the state of the background process and managing the alarms when the main activity is not running at all.  I see the need for two alarms: one to wake-up (or start) the background process every few minutes and one to shutdown the scheduled task after 
...
Mark M.
"Using the app Service lifecycle, will I be able to detect a re-started process versus an in-tact process?" -- um, you can see whether some static field is now null or something
assuming that the detection logic is in the process in question
Paul R.
OK, good enough for the first question.
Mark M.
I'm kinda puzzled by that question, though that may be the lack of sleep talking
Ron
has entered the room
Mark M.
"Does there need to be any coordination between an alarm (or scheduled job) and the onStartCommand() return value?" -- um, I can't really answer that
(BTW, hello, Ron -- I will be with you in a few minutes!)
Paul R.
Why were you puzzled?
7:30 PM
Mark M.
Paul: unclear what process is what
Paul R.
I see. I am only concerned with the process running the Service.
Mark M.
back to onStartCommand: its return value is fairly orthogonal to your proposed system, in that it feels like you plan on using stopSelf()/stopService() to stop the service
"After the processing timeout occurs (or a "done" state is reached), should the service be stopped?" -- I guess so
"How would I effectively leverage the Android Studio debugger to help develop this code?" -- I don't use multiple processes much, so I cannot really answer that
however, your assumptions are fundamentally flawed
unless by "every few minutes" you really mean "every several hours, when in Doze mode", or you are sure that you will be added to the battery optimization whitelist
Paul R.
I was not sure if I should use the sticky restart from the onStartCommand() or rely on the Alarm. Sounds like relying on the Alarm is good enough.
Mark M.
let me take a question from Ron, and I'll come back to you for more follow-up in a bit
Ron: your turn! do you have a question?
Ron
View paste
We were under the impression that the Application object is a singleton object that is the first thing created when the appA is run. We use it to store what amounts to Global objects so that other appA objects can reference them. Later on we added a Content Provider so that another of our apps, appB can access the data in appA via the provider. We noticed that the Application Object does not necessarily exist at the time the Content Provider is created. We found this odd. Our questions at this point:

1. Why is the Application object not created before the Content Provider since the <provide definition in the manifest.xml is contained within the <application definition?

2. Are Content Provider(s) always created first before the Application object or can it be random?
Mark M.
the Application singleton and the ContentProviders are created at the same time
in particular, onCreate() of the Application singleton will be called after onCreate() of the ContentProviders
if you have Application initialization that you have to do before the ContentProviders are created...
7:35 PM
Mark M.
...override attachBaseContext() and do it there (plus chain to the superclass)
Ron
That is what we thought but we couldn't find any confirmation. It verifies what we see. Okay we will try that?
Mark M.
you'll see this in the docs for ACRA, for example, as unless you it this way, ACRA won't be able to catch exceptions raised in onCreate() of the providers
this stuff is very undocumented
Ron
Okay, we will look at it. You can go to next question while I look...
Mark M.
OK
Paul: back to you!
Paul R.
So you seem to think that I need to ensure that Doze mode is taken into account. Does JobScheduler vs Alarm do this?
is one advantageous over the other?
Mark M.
well, both are affected by Doze mode
in theory, AlarmManager with setAndAllowWhileIdle() lets you kinda get past this
(also setExactAndAllowWhileIdle())
but that's still only every 15 minutes IIRC
and, you won't have Internet access, which presumably is part of what you're doing
Paul R.
Yes, internet is key.
Mark M.
I assume that your option #3 is really "poll the server every so often, looking for messages:
Paul R.
Yes.
Mark M.
Google's trying to get developers away from that, over to FCM
7:40 PM
Paul R.
Right. And they are even providing a new feature Firebase Cloud Functions.
Mark M.
yeah, I haven't heard of that, but I'm assuming its like AWS Lambda
Paul R.
that helps do that withut needing a compute or app engine cpu.
Mark M.
that fits my guess
Paul R.
Could be. I do not know ASW all that well.
Mark M.
though I'm not quite certain how you can use that for your situation
part of what the server needs to do, in a standard FCM setup, is record the FCM IDs of the clients
so that you know how to send messages out
with topic-based messages, I could see how FC Functions could perhaps work
but, I haven't looked at FCM in a couple of years, so I'm probably out of date
Paul R.
I'm worried about scaling. Using FCM with hundres of thousands of Users will not be cheap.
Mark M.
FCM itself is free, or at least it used to be
did they add a pricing model to it now?
Paul R.
The servers are not free.
Mark M.
but the server doesn't have to be on Firebase
your server could be a Raspberry Pi stuffed in an Altoids tin for all FCM cares
Paul R.
No but they need to be in the cloud
Mark M.
they have to be on the Internet
with a static IP address, and probably a domain name
IOW, no different than any other Web service, etc.
Paul R.
Yes, and I do not want to maintain them. Nor do a want a multi-thousand dollar monthly bill.
7:45 PM
Mark M.
um, if you have "hundreds of thousands of users", and you aren't making lots of money, you need to focus on the business model much more than on the tech
and, your option #3 needs a server anyway
Paul R.
It does?
How so?
Mark M.
um, what else were you planning on doing with the Internet, other than talking to a server?
Paul R.
Talking to the Frebase database is already part of the cost of doing business.
Mark M.
in your case, perhaps
Paul R.
The new Functions feature allows it to be a real server.
Mark M.
that statement gives me visions of Pinocchio
Paul R.
How so?
Mark M.
"then I can be a *real* boy!"
sorry, it was just a joke
Paul R.
np
Mark M.
I don't think you'll be able to pull off #3 unless they add you to the battery optimization whitelist
though you are welcome to run experiments and see if you can find some combination of stuff that avoids it
Paul R.
Firebase realizes that just providing a realtime db is not enough. So Functions are a cheap "I'm a server too" fix.
Mark M.
let me take another question from Ron, and I'll return to you shortly
Ron: back to you! do you have another questioon?
er, question?
7:50 PM
Ron
View paste
What is the status of Android Studio's debug capabilities when there are two modules in a Project and one of the models is a Android Library? Namely, if we are stepping through appA which then invokes a resource in the library (which is appB), can we single step through the Library code in debug as well? We have seen a lot on this and it doesn't seem to work and we found an open issue in Android which says that this will probably not be addressed until Studio 2.5. Can you confirm this?
7:50 PM
Paul R.
What would you do? (I'll take your answer in a minute)
Mark M.
I haven't had any problem setting breakpoints in a library module
I don't know that I have tried actually stepping from an app to a library module
but since I can step into JARs/AARs, I can't imagine that stepping from an app into a library module would somehow be a problem
perhaps your scenario is different than I am picturing, given your question
but most of my open source libraries come with a sample app or two
Ron
We need to debug together, appA is the primary app and we were able to construct appB into a library but we couldn't seem to get it to work. We saw a lot of SO entries saying that only release versions of libraries are compiled.
Mark M.
is this one project or two?
Ron
We are trying them in one project.
Mark M.
I haven't had a problem with that
maybe it's something about how I set up my projects
Ron
Can you point to an example anywhere?
Mark M.
my demo app uses debugCompile project(":name-of-library")
pretty much any of my CWAC projects
Ron
Where is that located?
Mark M.
Ron
Okay, we will look at those. You can go to next question.
7:55 PM
Mark M.
in those projects, you'll typically see two modules: a module named after the library (e.g., provider/) and an app module (e.g., demo/)
look at demo/build.gradle to see how I reference the library module
and, I'll come back to you for follow-up in a bit
Paul: over to you!
I can't really answer "what would you do", as I don't really know the overall scenario
I have my own reticence with respect to FCM, though in my case it's avoiding proprietary stuff
in your case, that's not an issue
whether you can get FCM to work in your circumstance, I can't say, as I don't really know what's going on
but FCM is the path of least resistance, in terms of Google providing resistance
Paul R.
I am inclined to try to manage battery drain for my initial release and use Firebase Functions when they are out of Beta.
fwiw.
Mark M.
the problem with "manage battery drain" is that you can't add the app to the battery optimization whitelist yourself -- the user has to do that
IIRC, you can find out whether you are on the whitelist (PowerManager, I think)
Paul R.
? I don't understand. The app is the User, is it not?
Mark M.
usually a human is a user
Paul R.
Or do you mean configure settings?
Mark M.
the human has to configure the Settings app to add your app to the device battery optimization whitelist
Paul R.
Ah, got it.
Mark M.
you cannot programmatically put yourself on that list
and if the human says no, you need to decide what to do
Paul R.
Yuck.
8:00 PM
Mark M.
well, if they didn't do that, the whitelist would be largely pointless
because every developer would just programmatically add their app to it
Paul R.
I have no problem that they chose to do it that way, it is just that it is ugly for my Users.
Mark M.
yup
for certain types of apps, where the target audience is power users, it won't be a big deal
for apps that are aimed at a wider audience, it's not great
there are ways to lead the human to the right spot in Settings... but Google has banned developers from the Play Store if they think that the app should not be doing that
Paul R.
My app is aimed at grandparents and grandchildren. Not exactly power users ... maybe the grandchildren. :-)
Mark M.
oy
on the whole, I advise people to try to avoid periodic background work in general now, because the area is such a mess
Paul R.
Good to know.
Mark M.
or, consider periodic background work as an optimization, with manual options (e.g., refresh action bar item) as a visible possibility for users
in your case, it feels like the messaging is fairly central, in which case, you're between a rock and a hard place
FCM is the Google-approved solution, if you can figure out how you can swing it
Paul R.
I'll post a broader description to Stack Overflow. Keep an eye out for it. Might help you get to a million rep points. :-)
8:05 PM
Mark M.
um, OK
let me take another question from Ron, and I'll return to you in a bit
Ron: back to you -- do you have another question?
Paul R.
And my question about DroidCon Boston?
Ron
View paste

You've given me enough to work on for now. I'm signing off, many thanks!
Mark M.
(Paul: nope, they declined my proposal)
Ron
has left the room
Mark M.
and I may not be available that week anyway
Paul R.
OK. Thanks for your help. Talk to you later.
Mark M.
you're very welcome!
8:30 PM
Mark M.
that's a wrap for today's chat
per usual, the transcript will go up on https://commonsware.com/office-hours/ shortly
the next chat is Tuesday, 9am US Eastern
have a pleasant day!
Paul R.
has left the room
Mark M.
turned off guest access

Monday, March 6

 

Office Hours

People in this transcript

  • Mark Murphy
  • Paul Reilly
  • Ron