The comical part of my recent surgery was that my iPhone 5S kept dying, both before and after the surgery. Something is going on where the iPhone completely loses reception, and the only way to fix it — the only hope of fixing it — is to completely restore the phone using a secret handshake technique they taught me at the local Apple Store. (They also told me this technique only works about 10% of the time, and kindly suggested I buy a new iPhone because the 5S is almost four years old.)
android tips and tutorials
As a quick example of how to use a
Thread with a basic
Handler in an Android application, the following code creates a view where the text in the
TextView is updated to show the current date and time when the
Button is tapped.
Java source code
First, here’s the Java source code for a file class named
This is a list of Android code examples I’m starting to allow me to create rapid prototypes of Android applications using Android Studio. This is a very early list, I hope to be adding many more Android code snippets over time.
I am working on a way to rapidly mock up Android applications using Android Studio, i.e., to rapidly prototype Android applications on the fly, and little snippets of code help to make this happen. For instance, this snippet of code shows how to show a popup dialog to prompt a user to enter information into a text field:
If you’re interested in Android performance benchmarks, AndroidBenchmark.net seems to have some simple charts, like the image shown.
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 Activity 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: