android

android tips and tutorials

An example of Android StrictMode output (with improper database access)

I was just working with an example of how to use Android’s new Room Persistence Library, and the example I was working with ran some of its code on the main Android thread, also known as its “UI thread.” I knew this was bad, but I wanted to start with someone’s example, and then figure out a good way to get the Room method calls to run on a background thread, such as using an AsyncTask. (The Android docs don’t specify a “best practice” for this atm.)

The Android “adb shell list files permission denied” error

As a brief note, today I tried to list the files in my Android application, which was running on a physical Android device — a Nexus 9 — with this adb shell command:

adb shell com.alvinalexander.mybrowser ls /data/data/com.alvinalexander.mybrowser

When I did that, I got an Android/ADB “permission denied” error.

The short story is that a solution to this problem is to run the same command, but with the run-as argument, like this:

Android: How to reference a drawable image in XML (or Java)

When you need to reference a drawable image from an Android XML file, such as a layout or menu file, use this tag:

android:src="@drawable/myimage"

That assumes that you have a file named myimage.png in your res/drawable directories. As a more complete example, this shows how I reference an image named images_show.png in an Android menu item:

Instructions for filing an Android bug report

As a quick note (circa March 10, 2017 and Android 7), I filed an Android bug report recently, and when I did, one of the Android developers asked if I would file an Android bug report. To do so, they gave me these instructions:

“After reproducing the issue, navigate to developer settings, ensure ‘USB debugging’ is enabled, then enable ‘Bug report shortcut’. To take bug report, hold the power button and select the ‘Take bug report’ option. Note: Please upload the files to google drive and share the folder to android-bugreport@google.com, then share the link here.”

I thought that was interesting, I had never seen the “Bug report shortcut” approach before.