From 7e9b794c7f099300d346c4c3163b97031d03bdd1 Mon Sep 17 00:00:00 2001 From: zlzw <583819556@qq.com> Date: Mon, 31 Oct 2022 14:59:14 +0800 Subject: [PATCH] =?UTF-8?q?AbsActivity=E6=96=B0=E5=A2=9E=E4=BD=8E=E5=86=85?= =?UTF-8?q?=E5=AD=98=E5=9B=9E=E8=B0=83=20DeviceUtils=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=BD=93=E5=89=8D=E5=BA=94=E7=94=A8=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=A4=84=E4=BA=8E=E4=BD=8E=E5=86=85=E5=AD=98=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yunbao/common/activity/AbsActivity.java | 16 ++++++++++++++-- .../com/yunbao/common/utils/DeviceUtils.java | 11 +++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) 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