LifeCycles

This section is mostly about AsyncTask and SavedInstancedState. Things most devs would encounter naturally.

However, I did learn about the AsyncTaskLoader. This is particularly useful for things like network calls, if the user rotates the device or switches to a different app while an AsyncTask is running, the Loader makes sure that there aren’t loose Async Threads hanging around.

Most of this is made redundant by the Networking Libraries like OKHTTP, or by using Observer/Eventbus patterns with things like RxJava or EventBus, but it’s good to know this exists, at least until I get a good handle on RxJava.

Preferences

I never knew about PreferencesFragment! You just feed it an XML file of preferences, and then it generates a generic preferences screen which automatically saves to SharedPreferences. I love it.

Not really good enough according to most designers, who insist on their own standards of good UX, but good enough for MVPs, or for any developer (such as myself) who lack the design skills to make anything original.

I also learned about OnSharePreferenceChangeListener. Very useful listener to implement in any activity if you don’t want to change anything in your UI unless sharedPreferences has changed. In fact, that gives me an idea for a “shouldParentClassRefresh” setting, which forces a refresh if any data has changed, if you don’t want to do the whole rigmarole of passing data back through onActivityResult, or EventBus. Not best practice, but useful as a hacky shortcut.

You can set a onPreferenceChangeListener on a specific preference, to act as validator before the preference is saved.

Next up is Sqlite, followed by Content Providers. Since  there are often issues with that (especially the ever-unreliable SugarORM), I’m looking forward to this one.


Leave a Reply