AbsActivity新增低内存回调
DeviceUtils新增获取当前应用是否处于低内存判断方法
This commit is contained in:
parent
e70a5e09f6
commit
7e9b794c7f
@ -10,6 +10,7 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.KeyCharacterMap;
|
import android.view.KeyCharacterMap;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@ -54,8 +55,8 @@ public abstract class AbsActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
Intent intent=getIntent();
|
Intent intent = getIntent();
|
||||||
if(intent!=null) {
|
if (intent != null) {
|
||||||
isFullWindow = getIntent().getBooleanExtra("isFull", false);
|
isFullWindow = getIntent().getBooleanExtra("isFull", false);
|
||||||
if (isFullWindow) {
|
if (isFullWindow) {
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||||
@ -358,4 +359,15 @@ public abstract class AbsActivity extends AppCompatActivity {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrimMemory(int level) {
|
||||||
|
super.onTrimMemory(level);
|
||||||
|
Log.i("memory", "onTrimMemory: " + level);
|
||||||
|
switch (level) {
|
||||||
|
case TRIM_MEMORY_RUNNING_CRITICAL://内存低值危险值
|
||||||
|
break;
|
||||||
|
case TRIM_MEMORY_RUNNING_LOW://内存过低
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.yunbao.common.utils;
|
package com.yunbao.common.utils;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.pm.PackageInfo;
|
import android.content.pm.PackageInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
@ -69,4 +70,14 @@ public class DeviceUtils {
|
|||||||
return "0";
|
return "0";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前是否处于低内存状态
|
||||||
|
*/
|
||||||
|
public static boolean isLowMemory(Context context) {
|
||||||
|
ActivityManager am = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||||
|
ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
|
||||||
|
am.getMemoryInfo(mi);
|
||||||
|
return mi.lowMemory;// 将获取的内存大小规格化
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user