diff --git a/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java b/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java index 12c926cf88..ada89c3e40 100644 --- a/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java +++ b/lib/DevApp/src/main/java/dev/utils/app/permission/PermissionUtils.java @@ -16,7 +16,6 @@ import androidx.core.app.ActivityCompat; import androidx.core.content.PermissionChecker; -import java.lang.ref.WeakReference; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; @@ -155,7 +154,7 @@ public void request(final Activity activity, final int requestCode) { if (checkPermissions(activity) == 1) { // 如果 SDK 版本大于 23 才请求 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { - sInstance = new WeakReference<>(this); + sInstance = this; // 请求权限 String[] permissions = mPermissionsRequestLists.toArray(new String[mPermissionsRequestLists.size()]); // 判断请求方式 @@ -199,7 +198,7 @@ public interface PermissionCallBack { // ================ // 内部持有对象 - private static WeakReference sInstance; + private static PermissionUtils sInstance; /** * detail: 请求权限 Activity @@ -225,10 +224,9 @@ protected static void start(final Context context) { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - if (sInstance != null && sInstance.get() != null) { // 请求权限 - int size = sInstance.get().mPermissionsRequestLists.size(); - requestPermissions(sInstance.get().mPermissionsRequestLists.toArray(new String[size]), 1); - } + // 请求权限 + int size = sInstance.mPermissionsRequestLists.size(); + requestPermissions(sInstance.mPermissionsRequestLists.toArray(new String[size]), 1); } /** @@ -239,9 +237,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { */ @Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { - if (sInstance != null && sInstance.get() != null) { // 处理回调 - sInstance.get().onRequestPermissionsResultCommon(this); - } + sInstance.onRequestPermissionsResultCommon(this); // 处理回调 finish(); // 关闭当前页面 } } @@ -264,8 +260,8 @@ private void onRequestPermissionsResultCommon(final Activity activity) { * @param activity {@link Activity} */ public static void onRequestPermissionsResult(final Activity activity) { - if (activity != null && sInstance != null && sInstance.get() != null) { // 触发回调 - sInstance.get().onRequestPermissionsResultCommon(activity); + if (activity != null && sInstance != null) { // 触发回调 + sInstance.onRequestPermissionsResultCommon(activity); } }