监控Activity在前后台状态的切换
public class BaseActivity extends Activity{
@Override
protected void onStop() {
boolean isOnForeground=isAppOnForeground();
RaiingLog.d("前后台测试-->>onStop-->>" + isAppOnForeground()+", name-->>"+this.getClass().getName()+", isShowDialog-->>"+isShowDialog);
super.onStop();
} @Override
protected void onResume() {
super.onResume();
boolean isOnForeground=isAppOnForeground();
RaiingLog.d("前后台测试-->>onResume-->>" + isAppOnForeground()+", name-->>"+this.getClass().getName()+", isShowDialog-->>"+isShowDialog); }
/**
* 程序是否在前台运行
*
* @return
*/
public boolean isAppOnForeground() {
// Returns a list of application processes that are running on the
// device ActivityManager activityManager = (ActivityManager) getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
String packageName = getApplicationContext().getPackageName(); List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager
.getRunningAppProcesses();
if (appProcesses == null)
return false; for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
// The name of the process that this object is associated with.
if (appProcess.processName.equals(packageName)
&& appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
return true;
}
} return false;
}
}
监控Activity在前后台状态的切换的更多相关文章
- android切换前后台状态监听
public class BaseApplication extends Application { private static BaseApplication instance; /** * 当前 ...
- [视频监控]用状态机图展示Layout切换关系
监控系统通常会提供多种Layout给用户,用于满足不同需求,如:高清显示单路视频或者同时观察多路监控情况. 文中系统只提供了单路.2x2(2行2列共4路).8路(4行4列布局,从左上角算起,有个核心显 ...
- Android软键盘状态的切换及其强制隐藏
MainActivity例如以下: package cc.c; import android.os.Bundle; import android.view.View; import android.v ...
- Activity的保存状态和状态恢复
Activity的保存状态和状态恢复 当系统内存不足时,系统会强制结束一些不可见的Activity以节省内存资源.在某些情况下,当被强制结束的Activity再次显示时会出现一些问题. 例如:一个AP ...
- 监控mysql主从同步状态脚本
监控mysql主从同步状态脚本 示例一: cat check_mysql_health #!/bin/sh slave_is=($(mysql -S /tmp/mysql3307.sock -uroo ...
- 采用Opserver来监控你的ASP.NET项目系列(三、监控你的服务器状态)
前言 之前有过2篇关于如何监控ASP.NET core项目的文章,有兴趣的也可以看看. 今天我们主要来介绍一下,如何使用Opserver监控我们的服务器状态. Opserver的功能其实很强大,他可以 ...
- [记录]Zabbix3.4配置监控Oracle12c的存活状态和表空间使用率
Zabbix3.4配置监控Oracle的存活状态和表空间使用率 1.安装zabbix3.4 agent: # rpm -ivh http://repo.zabbix.com/zabbix/3.4/rh ...
- Animator状态快速切换问题
[Animator状态快速切换问题] 事情是这样的,我尝试在一帧内多次切换一些状态(当前状态为Idle的情况下): public Animator animator; void OnEnable() ...
- shell习题第8题:监控nginx的502状态
[题目要求] 服务器上跑的是LNMP环境,近期总是有502现象.502为网站访问的状态码,200正常,502错误是nginx最为普遍的错误状态码. 由于502只是暂时的,并且只要一重启php-fpm服 ...
随机推荐
- boost.log要点笔记
span.kw { color: #007020; font-weight: bold; } code > span.dt { color: #902000; } code > span. ...
- 关于jquery获取服务器端xml数据
其实这个很简单,但是有时候简单的东西会让你犯一些低级错误. 今天写了个spring mvc 的服务器端接口,主要是用来共享一些数据库数据. 请求字段:http://localhost:8080/XXX ...
- [转载]Access to the path '' is denied.解决方案
原文地址:Access to the path '' is denied.解决方案作者:趴着墙等红杏 ccess to the path '路径' is denied.我在网上找了很多资料,最后终于解 ...
- JS 时间格式化函数
//时间格式化函数 Date.prototype.format = function (format) { var o = { "M+": this.getMonth() + 1, ...
- Lucene技术杂谈
Lucene教程 1 lucene简介 1.1 什么是lucene Lucene是一个全文搜索框架,而不是应用产品.因此它并不像www.baidu.com 或者google Desktop那么 ...
- 如何写robots.txt?
robin 发表在 八月 2, 2006 在国内,网站管理者似乎对robots.txt并没有引起多大重视,应一些朋友之请求,今天想通过这篇文章来简单谈一下robots.txt的写作. robots.t ...
- 使用methodSignatureForSelector与forwardInvocation实现消息转发 (转)
转自:http://blog.sina.com.cn/s/blog_8c87ba3b0102v006.html 在给程序添加消息转发功能以前,必须覆盖两个方法,即methodSignatureForS ...
- The version of CocoaPods used to generate the lockfile (*) is higher than the version of the current executable (*). Incompatibility issues may arise.
解决方法: sudo gem update cocoapod
- PHP过滤常用标签的正则表达式
$str=preg_replace("/\s+/", " ", $str); //过滤多余回车 $str=preg_replace("/<[ ] ...
- [Lua]索引极致,form.lua
local form = {_tag = 'form'} function form.build(tag, super) local target = { _tag = tag, _super = s ...