zoukankan      html  css  js  c++  java
  • Android开发检测App从后台进入前台的解决方法

    public class ActLifecycle implements ActivityLifecycleCallbacks {
    
      private int mPreActivityStartedCount = 0;
      private int mActivityStartedCount = 0;
      private int mActivityOrientation = Configuration.ORIENTATION_UNDEFINED;
    
      @Override
      public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
      }
    
      @Override
      public void onActivityStarted(Activity activity) {
        mPreActivityStartedCount = mActivityStartedCount;
        mActivityStartedCount++;
        int orientation = getOrientation(activity);
        if (mPreActivityStartedCount == 0 && mActivityStartedCount == 1
            && orientation == mActivityOrientation) {
          handleAppForeground(activity);//app从后台进入前台了,在这个自定义的方法里处理具体的业务
        }
        mActivityOrientation = orientation;
      }
    
      private int getOrientation(Activity activity) {
        if (activity != null && activity.getResources() != null) {
          Configuration configuration = activity.getResources().getConfiguration();
          if (configuration != null) {
            return configuration.orientation;
          }
        }
        return Configuration.ORIENTATION_UNDEFINED;
      }
    
      @Override
      public void onActivityResumed(Activity activity) {
      }
    
      @Override
      public void onActivityPaused(Activity activity) {
      }
    
      @Override
      public void onActivityStopped(Activity activity) {
        mPreActivityStartedCount = mActivityStartedCount;
        mActivityStartedCount--;
      }
    
      @Override
      public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
      }
    
      @Override
      public void onActivityDestroyed(Activity activity) {
      }
    }

    //注册app生命周期回调函数
    application.registerActivityLifecycleCallbacks(new ActLifecycle());
     
  • 相关阅读:
    python打印出当下的小时、分钟
    flask_ajax登录注册
    flask_SQlalchemy的复杂使用
    flask使用现有的数据表、在网页中显示数据
    js 的DOMdocument的使用
    pymysql的是使用
    通过ajax修改div id="div1" 的值
    关于django2.2使用xadmin的方法
    DOS windows 使用bat脚本获取 IP MAC 系统信息
    apache https 双向证书生成
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/10986310.html
Copyright © 2011-2022 走看看