如何确定Android应用程序当前是否正在使用?
我的应用程序在使用时会占用大量内存。我想在应用程序未使用时释放内存 我已经实现了如何确定Android应用程序当前是否正在使用?,android,memory,Android,Memory,我的应用程序在使用时会占用大量内存。我想在应用程序未使用时释放内存 我已经实现了Application.ontrimmory()。但是,即使我的应用程序当前正在使用,也会调用此方法(向用户显示活动)。如何确定我的应用程序的任何活动当前是否处于活动状态 minSdkVersion=“9”使用此简单方法检查应用程序是否在前台运行 public boolean isAppForground() { ActivityManager mActivityManager = (Activit
Application.ontrimmory()
。但是,即使我的应用程序当前正在使用,也会调用此方法(向用户显示活动)。如何确定我的应用程序的任何活动当前是否处于活动状态
minSdkVersion=“9”使用此简单方法检查应用程序是否在前台运行
public boolean isAppForground() {
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
List<RunningAppProcessInfo> l = mActivityManager.getRunningAppProcesses();
Iterator<RunningAppProcessInfo> i = l.iterator();
while (i.hasNext()) {
RunningAppProcessInfo info = i.next();
if (info.uid == getApplicationInfo().uid && info.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
return true;
}
}
return false;
}
public boolean isAppForground(){
ActivityManager MacActivityManager=(ActivityManager)getSystemService(Context.ACTIVITY_服务);
List l=mActivityManager.getRunningAppProcesses();
迭代器i=l.迭代器();
while(i.hasNext()){
RunningAppProcessInfo=i.next();
if(info.uid==getApplicationInfo().uid&&info.importance==RunningAppProcessInfo.importance\u前台){
返回true;
}
}
返回false;
}