android

  • 判断应用是否在前台 使用activityManager与当前页面线程对比
    • Code:
      /** 
      * 需要权限:android.permission.GET_TASKS 
      * 
      * @param context 
      * @return 
      */
      public boolean isApplicationBroughtToBackground(Context context) 
      { 
       ActivityManager am = (ActivityManager) context 
             .getSystemService(Context.ACTIVITY_SERVICE); 
       List<RunningTaskInfo> tasks = am.getRunningTasks(1); 
       if (tasks != null && !tasks.isEmpty()) 
       { 
         ComponentName topActivity = tasks.get(0).topActivity; 
         Debug.i(TAG, "topActivity:" + topActivity.flattenToString()); 
         Debug.f(TAG, "topActivity:" + topActivity.flattenToString()); 
         if(!topActivity.getPackageName().
               equals(context.getPackageName())) 
         { 
           return true; 
         } 
       } 
       return false; 
      } 
      链接:http://www.jb51.net/article/67656.htm
      

results matching ""

    No results matching ""