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.
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 👇
- Here, I will discuss only reason, you can learn more about the ApplicationExitInfo object here
- Reason can be one of the following :
- Enough discussion let’s see an example code how we can use it in real world applications:
- This code 👆will create the following 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;