java - Android 中 ActivityManager.getRecentTasks() 的替代方案?

标签 java android android-activity

目前,我发现通过 android 框架检索最近启动的应用程序历史记录的唯一方法是使用 ActivityManager.getRecentTasks()

自从 Android 文档站点 UI 大修后,我现在看到已将注释添加到此方法中:

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.

实现此目的更安全的替代方法是什么?

最佳答案

Lollipop 弃用了该方法;但是,有一个新的 API 允许您查看应用程序使用情况。

UsageStatsManager 有一些有用的方法来查看时间间隔之间的 Activity 。 希望这足以满足您的需求!

https://developer.android.com/reference/android/app/usage/package-summary.html

关于java - Android 中 ActivityManager.getRecentTasks() 的替代方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11979830/

相关文章:

android - 如何显示从数据库检索内容的通知?

android - 如何使用 JAM 和 Intel XDK 添加声音

java - Android 开发 : "R cannot be resolved", 但仅在类中的一个上下文中

当我尝试进行计算时,Java 无法识别 double

java - 计算数组中值的总和

Java,如何避免 "might not have been initialized"

作为额外传递的 Android 应用程序 : Runtime error when I try to get the Parcelable,

android - 为什么不能将 INT 保存到 SharedPreferences?

android - 使用静态方法创建 AlertDialog?

java - Hotspot 中的逃逸分析在简单情况下有多脆弱,例如 for-each 循环中的迭代器