Get App crash info using getHistoricalProcessExitReasons

Story header

Today we will learn about the new feature provided by ActivityManager in API 30. Which helps us to get an information related to application crashes.

Method that provides the information about the crashes

It has 3 parameters :

  • packageName: Optional, a null value means match all packages belonging to the caller’s UID. We provides application package name here.
  • pid: A process ID that used to belong to this package but died later; a value of 0 means to ignore this parameter and return all matching records. It can be ≥0.
  • maxNum: It represents maximum number of results to be returned; a value of 0 means to ignore this parameter and return all matching records. It can be ≥ 0.

As you have seen above that getHistoricalProcessExitReasons method returns MutableList of type ApplicationExitInfo.

Let's check what information ApplicationExitInfo object provides us.

  • There is a lot of information that it provides us related to crash 👇
Information provided by ApplicationExitInfo object
  • Here, I will discuss only reason, you can learn more about the ApplicationExitInfo object here
  • Reason can be one of the following :
Crash reasons
  • Enough discussion let’s see an example code how we can use it in real world applications:
MainActivity.kt Source code
  • This code 👆will create the following crashes : 💥💥💥💥
crashes
// App process died because of an unhandled exception in Java code.
REASON_CRASH = 4;

// App process was killed due to being unresponsive (ANR).
REASON_ANR = 6;

Stay in touch :

👏👏 👏👏 👨‍💻👩‍💻 Happy Coding 👩‍💻👨‍💻 👏👏👏👏

Mobile Software Engineer at Manulife. GDG Organizer at GDG Montreal.