/**
* 添加不被清理的后台应用
*
* @param packageName
*/
public void addBackgroundAliveApp(String packageName) {
List<String> list = getBackgroundAliveAppList();
if (list != null && packageName != null && packageName.length() > 0) {
if (!list.contains(packageName)) {
list.add(packageName);
}
setBackgroundAliveAppList(list);
}
}
/**
* 移除不被清理的后台应用
*
* @param packageName
*/
public void removeBackgroundAliveApp(String packageName) {
List<String> list = getBackgroundAliveAppList();
if (list != null && packageName != null && packageName.length() > 0) {
if (list.contains(packageName)) {
list.remove(packageName);
}
setBackgroundAliveAppList(list);
}
}
/**
* 获取不被清理的后台应用列表
*
* @return
*/
public List<String> getBackgroundAliveApps() {
List<String> list = getBackgroundAliveAppList();
return list;
}
补充代码
public static List<String> getWhiteAppProcessList() {
List<String> list = new ArrayList();
String sizeKey = "persist.test.aliveapps_s";
String valKey = "persist.test.aliveapps_";
int size = 0;
try
{
size = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if(size>0)
{
for(int i=0;i<size;i++)
{
list.add(SystemProperties.get(valKey+i));
}
}
return list;
}
public static void setWhiteAppProcessList(List<String> whiteAppProcessList) {
if(whiteAppProcessList==null || whiteAppProcessList.size()==0)
{
whiteAppProcessList = new ArrayList();
}
String sizeKey = "persist.test.aliveapps_s";
String valKey = "persist.test.aliveapps_";
int orgSize = 0;
try
{
orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if (orgSize > 0) {
for(int i=0;i<orgSize;i++)
{
SystemProperties.set(valKey+i,"");
}
}
int size = whiteAppProcessList.size();
SystemProperties.set(sizeKey,String.valueOf(size));
for(int i=0;i<size;i++)
{
SystemProperties.set(valKey+i,whiteAppProcessList.get(i));
}
}
public static List<String> getBackgroundAliveAppList() {
String sizeKey = "persist.test.backgroundapps_s";
String valKey = "persist.test.backgroundapps_";
List<String> list = new ArrayList();
int size = 0;
try
{
size = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if(size>0)
{
for(int i=0;i<size;i++)
{
list.add(SystemProperties.get(valKey+i));
}
}
return list;
}
public static void setBackgroundAliveAppList(List<String> backgroundAliveAppList) {
if(backgroundAliveAppList==null || backgroundAliveAppList.size()==0)
{
backgroundAliveAppList = new ArrayList();
}
String sizeKey = "persist.test.backgroundapps_s";
String valKey = "persist.test.backgroundapps_";
int orgSize = 0;
try
{
orgSize = Integer.parseInt(SystemProperties.get(sizeKey));
}
catch(Exception e)
{
}
if (orgSize > 0) {
for(int i=0;i<orgSize;i++)
{
SystemProperties.set(valKey+i,"");
}
}
int size = backgroundAliveAppList.size();
SystemProperties.set(sizeKey,String.valueOf(size));
for(int i=0;i<size;i++)
{
SystemProperties.set(valKey+i,backgroundAliveAppList.get(i));
}
}
转载请注明出处高通Android 12/13添加/移除不被清理后台应用-CSDN博客,谢谢!