And here we get to the server-client-database relationship, and how to handle these things. It seems quite obvious, but it’s amazing to me how many apps (including almost all of the ones I’ve worked on), tie all of the API calls closely to the Activity lifecycle. It should really be unacceptable to do that, but I guess if you’re going for quick results rather than perfect UI, that works.
This chapter has basic content about Services, IntentServices, and Noitifications. They don’t make it very clear in the course, but IntentServices are great for “fire and forget” operations, while Services are more involved. Quite useful info for an Android dev, and I’ve never seen anyone use an IntentService before, so I’m considering it.
They also go into ForegroundServices, which are Services that display a constant notification because they need to be constantly ongoing/visible to the User. An example might be uploading an image in the background while the app is closed, or playing music.
JobScheduler is mentioned, but FireBaseJobDispatcher is preferred since it has better backwards compatibility. And finally, BroadcastReceiver is explained.
This is a good course, I’m actually learning minutia and subtlety about the different classes I’ve been using or wanting to use, but haven’t quite figured out yet. I really like this course.
If you ever need a reference on how to handle periodic syncing of data in the background, with notifications included, use this reference on Github.
I learned about getQuantityString. It’s awesome. You define an array of possible plural strings, and then the getQuantityString method will give the correct String resource based on the number. Like so:
<plurals name="thing_has_been_done"> <item quantity="zero">This thing has been done %d times</item> <item quantity="one">This thing has been done %d time</item> <item quantity="other">This thing has been done %d times</item> </plurals>
String formattedNumberString = getResources().getQuantityString(R.plurals.thing_has_been_done, count, count);