判断当前应用程序处于前台还是后台
2015-12-28 10:33
225 查看
/**
*判断当前应用程序处于前台还是后台
*/
public static boolean isApplicationBroughtToBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
*判断当前应用程序处于前台还是后台
*/
public static boolean isApplicationBroughtToBackground(final Context context) {
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> tasks = am.getRunningTasks(1);
if (!tasks.isEmpty()) {
ComponentName topActivity = tasks.get(0).topActivity;
if (!topActivity.getPackageName().equals(context.getPackageName())) {
return true;
}
}
return false;
}
相关文章推荐
- php结合安卓客户端实现查询交互实例
- Android安卓中循环录像并检测内存卡容量
- 在安卓系统中插入表情到光标位置的代码详解
- Almp 安卓系统上搭建本地php服务器环境的步骤
- 谷歌被屏蔽后如何搭建安卓环境
- 安卓APP测试之使用Burp Suite实现HTTPS抓包方法
- 安卓(Android)聊天机器人实现代码分享
- 分享一个安卓的内置多种工具类的Activity
- 安卓系统中实现摇一摇画面振动效果的方法
- java实现获取安卓设备里已安装的软件包
- 安卓(Android)中如何实现滑动导航
- 六款值得推荐的android(安卓)开源框架简介
- android(安卓)开源框架——六款【转】
- java.lang.NoClassDefFoundError: org.apache.axis.cl
- 浅谈Android虚拟机的动态加载技术
- 安卓系统手机无法连接***
- android intent和intent action大全