Android: Always show toasts on the background thread

I used to call Toast#show() on the UI thread. Then one day, I received notifications related to an ANR (Application Not Responding) error in one of my Android apps. Java 1 2 3 4 5 6 7 8 9 10 11 at android.os.BinderProxy.transactNative(BinderProxy.java) at android.os.BinderProxy.transact(BinderProxy.java:605) at android.view.accessibility.IAccessibilityManager$Stub$Proxy.addClient(IAccessibilityManager.java:1207) at android.view.accessibility.AccessibilityManager.tryConnectToServiceLocked(AccessibilityManager.java:1804) at android.view.accessibility.AccessibilityManager.(AccessibilityManager.java:606) at android.widget.ToastPresenter.(ToastPresenter.java:138) at android.widget.Toast$TN.(Toast.java:1151) at android.widget.Toast.(Toast.java:259) at android.widget.Toast.makeText(Toast.java:891) at android.widget.Toast.makeText(Toast.java:879) at net.ashishb.androidmusicplayer.util.UiHelper.showToast(UiHelper.java:111) Programmers on StackOverflow are confused about whether it is OK to call Toasts on the background threads....

How to deploy Docker images on Microsoft Azure

There are several ways to deploy Docker images on Microsoft Azure. My favorite one is Azure App Service/Web Application for Containers. This is the closest to Google Cloud Run.

End-to-end testing of mobile apps

Google released a new version of the Google Auth library. It had a bug that broke Google Login on Android for API 26 and earlier. This impacted my small but popular Music Player app in Google Play. It reveals the kind of problem, I have alluded to in end-to-end testing. The only way to avoid such problems is by end-to-end testing. However, I find all Android testing frameworks to be terrible....

API backend should use dataloaders

Data Loaders allow transparent batching of requests to a data provider (e.g. database). More often than not, this leads to reduced latency and better performance without forcing an explicit batching of requests for the API users, for example, your frontend developers. Many programmers relate data loaders to Graph QL for N+1 query patterns. I believe data loaders are a great idea any time you are building an API backend. Let me illustrate the concept with a simple example. And while I am using Go as an example, data loader implementations are available in many languages.

Generics in Go

Generics in Go were added about a year back in Go 1.18. In my experience they are great and they fix one of the biggest roadblocks in terms of writing reusable code in Go. I鈥檒l illustrate that with an example. First, do ensure that you have at least Go 1.18 Bash 1 2 $ go version go version go1.19.1 darwin/amd64 Let鈥檚 consider a simple case of implementing a Map function in Go that maps an array (well, a slice) to another array (again, actually, a slice)....

Common pitfalls of GitHub Actions

If you create GitHub Actions via GitHub鈥檚 UI by going to the URL of the form `https://github.com///actions/new`, it provides templates for setting up the build. However, the template is broken. There are four problems with the default template

Inheritance in Go language

Go language does not have the concept of a class directly. It, however, has a concept of an interface as well as a struct. I鈥檒l illustrate how this can be used to build most of the inheritance constructs that a language like Java or C++ offers.

GraphQL vs gRPC

RPC calls allow one service to call functions in another service as if it is a part of the same service. And unlike a REST API, one gets strong type checking. The two services can even be in different languages.聽gRPC is a great framework for implementing an RPC service. Another language-agnostic framework for making RPC calls is GraphQL. Many people don鈥檛 think of GraphQL that way, however, it can serve the same purpose....

Android uncaught exception handler and ANR

While trying to install a custom exception handler to catch uncaught exceptions (crashes), I ended up writing

Infinite network timeouts in Java and Go

Java made a huge mistake of having no network timeouts. A network request can block a thread forever. Even Python did the same. The language designers should have chosen some conservative appropriate numbers instead. What鈥檚 surprising is that the Go language repeated it!聽Here鈥檚 a simple demo