Note: This page isn’t really for other people. I use it as the home page for my FLiB Android browser.
android tips and tutorials
I just started working with the Android Room database persistence library, and since you’re not supposed to run things like database queries on the main thread (the UI thread), I was looking at other ways to run them.
In general, you probably won’t want to run database queries using a
Thread, but just to see how Room works, I wrote this Java Thread code, and confirmed that it works as expected:
To show an Android Snackbar message from an Acitivity or Fragment, use Java code like this:
Snackbar.make(view, "going to: " + url, Snackbar.LENGTH_LONG).show();
One key is to remember to call the
show() method after
make(). I have a tendency to forget to call
show() and then wonder why my Snackbar message isn’t showing up. So maybe a better way to show that code is like this:
This is a good article that shows several different ways to handle background tasks in Android, including
- Java threads
- Android HandlerThread
- Java Timer
Android FAQ: When is the Android Fragment
onCreateOptionsMenu method called?
I was just working through a problem with an Android Menu and MenuItem, and added some debug code to the methods in my Android Fragment, and found that the
onCreateOptionsMenu method is called after
onStart. I didn’t put Log/debug code in every activity lifecycle method, but for the ones I did add logging code to, the specific order of the fragment method calls looked like this:
Android FAQ: How do I convert a list of strings (or a list of objects) to a single, combined string?
In Android, if you want to convert a list of strings to a
String, I just saw this approach:
Android 7 comes with a cool new “split screen” feature where you can look at two apps running at the same time. This little pictorial/tutorial shows how to use this split-screen feature.
I’ve currently written this document as a “note to self” about how the Android
AsyncTask works. It’s currently incomplete, but if you want to know how an AsyncTask works, most of the answers are generally here. I provide documentation for most aspects of the
AsyncTask, though my coverage of (a) updating progress/status and (b) canceling an
AsyncTask is a little weak atm.
I just got back into using an Android
AsyncTask, and it took me a little while to re-load the concepts in my head. I used
AsyncTask’s a few years ago, but haven’t used them since.
To help remember how they work, I created a little
AsyncTask example project, and I’ve included all of the source code for that project here. I’ll show all of the source code for my classes and configuration files, and then explain the code at the end.
As a note to self, here are some Android Room database persistence library examples:
Those tutorials don’t show how to properly use Room database access methods, so they’ll lead to Android “Application Not Responding” (ANR) errors. Therefore, here are some related Google/Android docs:
Finally, here’s my own Android AsyncTask REST example, which also shows how to use an