当前位置: 首页>>代码示例>>Java>>正文


Java RunningAppProcessInfo.IMPORTANCE_VISIBLE属性代码示例

本文整理汇总了Java中android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE属性的典型用法代码示例。如果您正苦于以下问题:Java RunningAppProcessInfo.IMPORTANCE_VISIBLE属性的具体用法?Java RunningAppProcessInfo.IMPORTANCE_VISIBLE怎么用?Java RunningAppProcessInfo.IMPORTANCE_VISIBLE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.app.ActivityManager.RunningAppProcessInfo的用法示例。


在下文中一共展示了RunningAppProcessInfo.IMPORTANCE_VISIBLE属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: cleanMemory

public static void cleanMemory(Context context){
    System.out.println("---> 清理前可用内存:"+getAvailMemory(context)+"MB");
    ActivityManager activityManager=(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

    List<ActivityManager.RunningAppProcessInfo> processList = activityManager.getRunningAppProcesses();

    if (processList != null) {
        for (int i = 0; i < processList.size(); ++i) {
            RunningAppProcessInfo runningAppProcessInfo= processList.get(i);
            // 一般数值大于RunningAppProcessInfo.IMPORTANCE_SERVICE
            // 的进程即为长时间未使用进程或者空进程
            // 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE
            // 的进程都是非可见进程,即在后台运行
            if (runningAppProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                String[] pkgList = runningAppProcessInfo.pkgList;
                for (int j = 0; j < pkgList.length; ++j) {
                    System.out.println("===> 正在清理:"+pkgList[j]);
                    activityManager.killBackgroundProcesses(pkgList[j]);
                }
            }

        }
    }
    System.out.println("---> 清理后可用内存:"+getAvailMemory(context)+"MB");
}
 
开发者ID:hubcarl,项目名称:mobile-manager-tool,代码行数:25,代码来源:StorageUtil.java

示例2: isActivityForeground

/**
 * check FM is foreground or background
 */
public boolean isActivityForeground() {
    boolean isForeground = true;
    List<RunningAppProcessInfo> appProcessInfos = mActivityManager.getRunningAppProcesses();
    for (RunningAppProcessInfo appProcessInfo : appProcessInfos) {
        if (appProcessInfo.processName.equals(mContext.getPackageName())) {
            int importance = appProcessInfo.importance;
            Log.d(TAG, "isActivityForeground importance:" + importance);
            if (importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND ||
                    importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                Log.d(TAG, "isActivityForeground is foreground");
                isForeground = true;
            } else {
                Log.d(TAG, "isActivityForeground is background");
                isForeground = false;
            }
            break;
        }
    }
    Log.d(TAG, "isActivityForeground return " + isForeground);
    return isForeground;
}
 
开发者ID:hyperion70,项目名称:android_device_MTS_x2605,代码行数:24,代码来源:FmRadioService.java

示例3: doInBackground

@Override
protected Void doInBackground(Void... params) {
    ActivityManager activityManager=(ActivityManager)mainActivity.getSystemService("activity");
    List<RunningAppProcessInfo> procInfo=activityManager.getRunningAppProcesses();
    for (int i=0;i<procInfo.size();i++)
    {
        RunningAppProcessInfo process=procInfo.get(i);
        int importance=process.importance;
        String name=process.processName;
        if(!name.equals("com.dev.system.monitor")&&
                !name.contains("launcher")&&
                !name.contains("googlequicksearchbox")&&
                importance>RunningAppProcessInfo.IMPORTANCE_VISIBLE)
            activityManager.killBackgroundProcesses(name);
    }
    return null;
}
 
开发者ID:Daniele-Comi,项目名称:System-Monitor,代码行数:17,代码来源:RAMManagement.java

示例4: getImportance

private String getImportance( RunningAppProcessInfo proc )
{
	String impt = "Empty"; //$NON-NLS-1$

	switch ( proc.importance )
	{
		case RunningAppProcessInfo.IMPORTANCE_BACKGROUND :
			impt = "Background"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_FOREGROUND :
			impt = "Foreground"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE :
			impt = "Perceptible"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_SERVICE :
			impt = "Service"; //$NON-NLS-1$
			break;
		case RunningAppProcessInfo.IMPORTANCE_VISIBLE :
			impt = "Visible"; //$NON-NLS-1$
			break;
	}

	return impt;
}
 
开发者ID:qauck,项目名称:qsysinfo,代码行数:25,代码来源:SysInfoManager.java

示例5: clearMemory

private void clearMemory() {
       ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE);  
       List<RunningAppProcessInfo> infoList = am.getRunningAppProcesses();  
       //List<ActivityManager.RunningServiceInfo> serviceInfos = am.getRunningServices(100);  

       long beforeMem = MyWindowManager.getAvailableMemory();  
       String TAG = "";
       Log.d(TAG, "-----------before memory info : " + beforeMem);  
       int count = 0;  
       if (infoList != null) {  
           for (int i = 0; i < infoList.size(); ++i) {  
               RunningAppProcessInfo appProcessInfo = infoList.get(i);  
               Log.d(TAG, "process name : " + appProcessInfo.processName);  
               //importance �ý��̵���Ҫ�̶�  ��Ϊ����������ֵԽ�;�Խ��Ҫ��  
               Log.d(TAG, "importance : " + appProcessInfo.importance);  

               // һ����ֵ����RunningAppProcessInfo.IMPORTANCE_SERVICE�Ľ��̶���ʱ��û�û��߿ս�����  
               // һ����ֵ����RunningAppProcessInfo.IMPORTANCE_VISIBLE�Ľ��̶��Ƿǿɼ����̣�Ҳ�����ں�̨������  
               if (appProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {  
                   String[] pkgList = appProcessInfo.pkgList;  
                   for (int j = 0; j < pkgList.length; ++j) {//pkgList �õ��ý��������еİ���  
                       Log.d(TAG, "It will be killed, package name : " + pkgList[j]);  
                       if (!"com.lazy.floatwindowdemo".equals(pkgList[j])) {
                       	am.killBackgroundProcesses(pkgList[j]);  
                           count++;  
					}
                   }  
               }  
           }  
       }

       long afterMem = MyWindowManager.getAvailableMemory();  
       Log.d(TAG, "----------- after memory info : " + afterMem);  
       Toast.makeText(context, "clear " + count + " process, "  
                   + (afterMem - beforeMem)/1024 + "M", Toast.LENGTH_LONG).show();
}
 
开发者ID:lazyprogramer,项目名称:FloatWindowKillProcess,代码行数:36,代码来源:FloatWindowBig.java

示例6: isAppOnForeground

/**
 * 判断程序是否在前台
 *
 * @return true 在前台; false 在后台
 */
private boolean isAppOnForeground() {
    if (!isSpecialSystem) {
        boolean isspecial = true;
        String packageName = context.getPackageName();
        List<RunningAppProcessInfo> appProcesses = activityManager.getRunningAppProcesses();
        if (appProcesses == null)
            return false;
        for (RunningAppProcessInfo appProcess : appProcesses) {
            if (appProcess.processName.equals(packageName)) {
                if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND || appProcess.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
                    return true;
                }
                if (keyguardManager.inKeyguardRestrictedInputMode()) return true;
            }
            if (isspecial) {
                if (appProcess.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
                    isspecial = false;
                }
            }
        }
        if (isspecial) {
            isSpecialSystem = true;
            return !isApplicationBroughtToBackgroundByTask();
        }
        return false;
    } else {
        return !isApplicationBroughtToBackgroundByTask();
    }
}
 
开发者ID:ownwell,项目名称:zztinews,代码行数:34,代码来源:AppRunningInBackground.java

示例7: isSPARunnung

public boolean isSPARunnung() {
	ActivityManager activityManager = (ActivityManager) getSystemService( ACTIVITY_SERVICE );
	List<RunningAppProcessInfo> procInfos = activityManager.getRunningAppProcesses();
	for( int i = 0; i < procInfos.size(); i++ ) {
		if( procInfos.get( i ).processName.equals( Constants.SPA_PACKAGE_NAME ) ) {
			if( procInfos.get( i ).importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND || procInfos.get( i ).importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE ) {
				return true;
			} else if( procInfos.get( i ).importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND && procInfos.get( i ).lru == Constants.BG_IMPORTANCE_LIVE ) {
				return true;
			}
		}
	}
	return false;
}
 
开发者ID:SilentCircle,项目名称:silent-text-android,代码行数:14,代码来源:ConversationListActivity.java

示例8: runProcessGC

private void runProcessGC() {
    if (mHostContext == null) {
        return;
    }
    ActivityManager am = (ActivityManager) mHostContext.getSystemService(Context.ACTIVITY_SERVICE);
    if (am == null) {
        return;
    }

    List<RunningAppProcessInfo> infos = am.getRunningAppProcesses();
    List<RunningAppProcessInfo> myInfos = new ArrayList<RunningAppProcessInfo>();
    if (infos == null || infos.size() < 0) {
        return;
    }

    List<String> pns = mStaticProcessList.getOtherProcessNames();
    pns.add(mHostContext.getPackageName());
    for (RunningAppProcessInfo info : infos) {
        if (info.uid == android.os.Process.myUid()
                && info.pid != android.os.Process.myPid()
                && !pns.contains(info.processName)
                && mRunningProcessList.isPlugin(info.pid)
                && !mRunningProcessList.isPersistentApplication(info.pid)
                /*&& !mRunningProcessList.isPersistentApplication(info.pid)*/) {
            myInfos.add(info);
        }
    }
    Collections.sort(myInfos, sProcessComparator);
    for (RunningAppProcessInfo myInfo : myInfos) {
        if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_GONE) {
            doGc(myInfo);
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_EMPTY) {
            doGc(myInfo);
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_BACKGROUND) {
            doGc(myInfo);
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_SERVICE) {
            doGc(myInfo);
        } /*else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_CANT_SAVE_STATE) {
            //杀死进程,不能保存状态。但是关我什么事?
        }*/ else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_PERCEPTIBLE) {
            //杀死进程
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
            //看得见
        } else if (myInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
            //前台进程。
        }
    }

}
 
开发者ID:amikey,项目名称:DroidPlugin,代码行数:49,代码来源:MyActivityManagerService.java

示例9: releaseRam

public static void releaseRam(Context context) {
	ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

	// To change body of implemented methods use File | Settings | File Templates.
	List<RunningAppProcessInfo> infoList = am.getRunningAppProcesses();
	List<RunningServiceInfo> serviceInfos = am.getRunningServices(100);

	long beforeMem = getAvailMemory(context);
	Log.i(TAG, "Before release, avail memory: " + beforeMem);

	int count = 0;

	for (int i = 0; i < infoList.size(); ++i) {
		RunningAppProcessInfo appProcessInfo = infoList.get(i);

		Log.d(TAG, "Process name: " + appProcessInfo.processName);

		// importance 该进程的重要程度 分为几个级别,数值越低就越重要。
		Log.d(TAG, "Importance: " + appProcessInfo.importance);

		// 一般数值大于RunningAppProcessInfo.IMPORTANCE_SERVICE 的进程都长时间没用或者空进程了
		// 一般数值大于RunningAppProcessInfo.IMPORTANCE_VISIBLE 的进程都是非可见进程, 也就是在后台运行着
		// 我这里选择阈值是IMPORTANCE_VISIBLE级别的,也就是非可见的后台进程和服务会被杀掉(一些系统进程肯定除外)。
		// 清理的效果跟金山清理大师和360桌面的一键清理效果差不多。
		// 如果不想杀的太凶,可以选择IMPORTANCE_SERVICE级别,杀掉那些长时间没用或者空进程了,
		// 这个级别的清理力度不够大,达不到金山清理大师的效果。
		if (appProcessInfo.importance > RunningAppProcessInfo.IMPORTANCE_VISIBLE) {
			String[] pkgList = appProcessInfo.pkgList;

			int length = pkgList.length;
			for (int j = 0; j < length; ++j) {// pkgList 得到该进程下运行的包名
				String packageName = pkgList[j];

				if (packageName.equals(context.getPackageName())) {
					continue;
				}

				Log.d(TAG, packageName + " will be killed.");

				am.killBackgroundProcesses(packageName);

				count++;
			}
		}
	}

	long afterMem = getAvailMemory(context);
	Log.i(TAG, "After release, avail memory: " + afterMem);

	Log.w(TAG, "Clear " + count + " processes, " + (afterMem - beforeMem) + "M released");
}
 
开发者ID:imknown,项目名称:IMKBaseFrameworkLibrary,代码行数:51,代码来源:DeviceUtil.java


注:本文中的android.app.ActivityManager.RunningAppProcessInfo.IMPORTANCE_VISIBLE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。