android

android tips and tutorials

Making the switch, from iPhone to Android alvin August 30, 2017 - 3:52pm

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: How to send a message from a Thread to a Handler

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 ThreadHandlerActivity:

Code snippets for rapid prototyping of Android Studio apps alvin August 28, 2017 - 7:22pm

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.

Android source code to show a popup dialog with a text field

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:

Android performance benchmarks alvin August 27, 2017 - 9:47pm

If you’re interested in Android performance benchmarks, AndroidBenchmark.net seems to have some simple charts, like the image shown.

Android Room, database I/O, and Java 8 threads alvin August 7, 2017 - 10:50am

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:

How to show an Android Snackbar message

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:

8 ways to do asynchronous processing in Android and counting alvin August 3, 2017 - 5:27pm

This is a good article that shows several different ways to handle background tasks in Android, including

  • AsyncTask
  • IntentService
  • Loader
  • JobScheduler
  • CountdownTimer
  • Java threads
  • Android HandlerThread
  • FutureTask
  • Java Timer
When is the Android Fragment onCreateOptionsMenu method called? alvin August 3, 2017 - 12:36pm

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:

FLiB Home Page alvin August 2, 2017 - 7:33pm

Note: This page isn’t intended for other people; I use it as the home page for my FLiB Android browser.