It’s been awhile since I’ve made a post so I thought I’d try and make a habit of adding tips on a regular basis, I’ve been kind of swamped. Anyway back to the topic: getRunningAppProcesses. It’s an ActivityManager method and it used to be used a lot by apps to check the processes running on a device but this functionality was nerfed from Lollipop onwards…

Even though it has become less useful over time you can still call this method and it will tell you the running processes for your own application(and that’s it). This can be good if you’re working with multiple(or remote) processes. You’d assume this method would return an empty list if there aren’t any running processes when it’s called…

Unfortunately that’s not the case.

Let’s take closer look at the developer documentation:

Returns a list of RunningAppProcessInfo records, or **null** if there are no running processes **(it will not return an empty list)**. This list ordering is not specified.

Depending on how you’re using this(like if you’re calling it from an Activity) the chances are pretty low there are going to be no running processes. However, using this method from the background could yield different results on certain devices – it seems to be pretty rare but I have witnessed it in Crash Reports before. That’s what lead me to writing this post.

So – in closing – if you’re using this method and not using Kotlin, be careful and make sure you add a sturdy null check.