zoukankan      html  css  js  c++  java
  • android切换前后台状态监听

    public class BaseApplication extends Application {
        private static BaseApplication instance;
        /**
         * 当前Activity个数
         */
        private int activityNumber = 0;
        @Override
        public void onCreate() {
            super.onCreate();
            registerActivityLifecycleCallbacks(activityLifecycleCallbacks);
            instance = this;
        }
    
        public static BaseApplication getInstance() {
            return instance;
        }
    
    
        /**
         * Activity 生命周期监听,用于监控app前后台状态切换
         */
        ActivityLifecycleCallbacks activityLifecycleCallbacks = new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
    
            }
    
            @Override
            public void onActivityStarted(Activity activity) {
                if (activityNumber == 0) {
                    LogUtil.i("app回到前台");
                }
                activityNumber++;
                LogUtil.i("activityNumber = " + activityNumber);
            }
    
            @Override
            public void onActivityResumed(Activity activity) {
            }
    
            @Override
            public void onActivityPaused(Activity activity) {
            }
    
            @Override
            public void onActivityStopped(Activity activity) {
                activityNumber--;
                LogUtil.i("activityNumber = " + activityNumber);
                if (activityNumber == 0) {
                    // app回到后台
                    LogUtil.i("app回到后台");
                }
            }
    
            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
            }
    
            @Override
            public void onActivityDestroyed(Activity activity) {
            }
        };
    
    }
    
  • 相关阅读:
    Lucene的分页查询
    Lucene索引库的简单优化
    Lucene的排序搜索
    Axure RP 6.5学习记录(1)界面介绍
    Lucene的高亮器Highlighter
    关于Lucene以及索引和搜索的流程
    Lucene初体验
    linux 下 ansi_x3.41968 java 邮件附件乱码
    SQL Server DBA工作内容详解
    SQL Server 导出 insert into 脚本
  • 原文地址:https://www.cnblogs.com/baiyi168/p/8252825.html
Copyright © 2011-2022 走看看