application 有用的监听
来源:互联网 发布:java可以清理cookie吗 编辑:程序博客网 时间:2024/06/05 07:11
public class MyApplication extends Application { // Starts as true in order to be notified on first launch private boolean isBackground = true; @Override public void onCreate() { super.onCreate(); listenForForeground(); listenForScreenTurningOff(); } private void listenForForeground() { registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() { //... @Override public void onActivityResumed(Activity activity) { if (isBackground) { isBackground = false; notifyForeground(); } } //... }); } private void listenForScreenTurningOff() { IntentFilter screenStateFilter = new IntentFilter(Intent.ACTION_SCREEN_OFF); registerReceiver(new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { isBackground = true; notifyBackground(); } }, screenStateFilter); } @Override public void onTrimMemory(int level) { super.onTrimMemory(level); if (level == TRIM_MEMORY_UI_HIDDEN) { isBackground = true; notifyBackground(); } } private void notifyForeground() { // This is where you can notify listeners, handle session tracking, etc } private void notifyBackground() { // This is where you can notify listeners, handle session tracking, etc } public boolean isBackground() { return isBackground; }}
0 0
- application 有用的监听
- onTouch事件的传递,以及一些很有用的监听
- application 启动定时监听
- 监听器(对application监听)
- Application整个运行当中需要用到的变量以及监听Activity的活动状态
- FLEX实践—模拟Application与Module间的事件监听
- 开发小技巧之在Application中监听App中的Activity的生命周期
- 有用的
- 有用的
- 有用的
- 有用的
- Application.Add、Application.RemoveAt、 Application.Remove、Application.Clear的用法
- 搜集的有用的
- web事件操作【监听器】之对application监听
- RevitAPI:监听文档改变ControlledApplication/Application.DocumentChanged事件
- SrpingMVC启动监听与普通类取Application
- 有用的GetForegroundWindow
- 有用的地址
- Weex开发笔记
- Query AJAX保存数据中文乱码解决方案
- Java ClassLoader深入讲解
- Palindrome Number Leetcode Python Java
- Session会在浏览器关闭后消失吗???
- application 有用的监听
- rhel6启动原理和故障排除
- java中的内存泄漏问题
- 生成类似激活码的代码(C#)
- git学习笔记--标签
- 图解 Android 事件分发机制
- Java流程控制
- [codevs1294] 全排列
- iOS开发中的一些常用方法(一)