How to Determine App Execution Status During FCM Development
During FCM development, I encountered a need for a logic to determine whether the app was running or not. Differentiating the app's execution status presented a significant challenge.
To simplify status verification, I developed the code described below. I believe this could be beneficial for others facing similar issues.
Add the Following Code in onCreate Within the Application Class Inheritance:
If 'activityStackCnt' is greater than 0, then the app is in the foreground. If 'activityStackCnt' equals 0, then it's in the background. This is how you can distinguish between them.
This logic was developed under the assumption that if an app is properly closed by pressing the back button, 'activityStackCnt' would reduce to zero. Interestingly, regardless of the current screen, if memory gets cleared by a task kill operation, 'activityStackCnt', being declared as static, is reset to its default value of zero. This solution worked quite well, perhaps somewhat serendipitously.
0 개의 댓글:
Post a Comment