diff --git a/common/src/main/java/com/yunbao/common/activity/AbsActivity.java b/common/src/main/java/com/yunbao/common/activity/AbsActivity.java index 482bd9b29..e75bf5ae6 100644 --- a/common/src/main/java/com/yunbao/common/activity/AbsActivity.java +++ b/common/src/main/java/com/yunbao/common/activity/AbsActivity.java @@ -10,6 +10,7 @@ import android.os.Build; import android.os.Bundle; import android.provider.Settings; import android.text.TextUtils; +import android.util.Log; import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.View; @@ -54,8 +55,8 @@ public abstract class AbsActivity extends AppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { - Intent intent=getIntent(); - if(intent!=null) { + Intent intent = getIntent(); + if (intent != null) { isFullWindow = getIntent().getBooleanExtra("isFull", false); if (isFullWindow) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); @@ -358,4 +359,15 @@ public abstract class AbsActivity extends AppCompatActivity { 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; + } + } } diff --git a/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java b/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java index 241c0fce7..afce551d2 100644 --- a/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/DeviceUtils.java @@ -1,6 +1,7 @@ package com.yunbao.common.utils; import android.app.Activity; +import android.app.ActivityManager; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; @@ -69,4 +70,14 @@ public class DeviceUtils { 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;// 将获取的内存大小规格化 + } } \ No newline at end of file