# Android 判断应用前后台运行状态并获取当前 Activity 实例

Android 5.0（Lollipop，API 21）之前，我们可以通过ActivityManager提供的getRunningTasks方法获取当前设备所有处于运行状态的应用信息，从而判断自己的应用的运行状态，包括topActivity信息，如：

Note: this method is only intended for debugging and presenting task management user interfaces. This should never be used for core logic in an application, such as deciding between different behaviors based on the information found here. Such uses are not supported, and will likely break in the future. For example, if multiple applications can be actively running at the same time, assumptions made about the meaning of the data here for purposes of control flow will be incorrect.

Note: this method is only intended for debugging or building a user-facing process management UI.

https://github.com/jaredrummler/AndroidProcesses

https://github.com/wenmingvs/AndroidProcess