Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复Context引用 引起的 内存泄漏问题 #267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class NavigationBarObserver extends ContentObserver {
static final String IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW = "navigationbar_is_min";

private ArrayList<OnNavigationBarListener> mListeners;
private Context context;
private Context mAppContext;
private Boolean mIsRegister = false;

public static NavigationBarObserver getInstance() {
Expand All @@ -39,9 +39,9 @@ private NavigationBarObserver() {
}

public void register(Context context) {
this.context = context.getApplicationContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && context != null
&& context.getContentResolver() != null && !mIsRegister) {
this.mAppContext = context.getApplicationContext();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mAppContext != null
&& mAppContext.getContentResolver() != null && !mIsRegister) {
Uri uri = null;
if (OSUtils.isMIUI()) {
uri = Settings.Global.getUriFor(IMMERSION_MIUI_NAVIGATION_BAR_HIDE_SHOW);
Expand All @@ -53,7 +53,7 @@ public void register(Context context) {
}
}
if (uri != null) {
context.getContentResolver().registerContentObserver(uri, true, this);
mAppContext.getContentResolver().registerContentObserver(uri, true, this);
mIsRegister = true;
}
}
Expand All @@ -62,16 +62,16 @@ public void register(Context context) {
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && context != null && context.getContentResolver() != null
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mAppContext != null && mAppContext.getContentResolver() != null
&& mListeners != null && !mListeners.isEmpty()) {
int show = 0;
if (OSUtils.isMIUI()) {
show = Settings.Global.getInt(context.getContentResolver(), IMMERSION_MIUI_NAVIGATION_BAR_HIDE_SHOW, 0);
show = Settings.Global.getInt(mAppContext.getContentResolver(), IMMERSION_MIUI_NAVIGATION_BAR_HIDE_SHOW, 0);
} else if (OSUtils.isEMUI()) {
if (OSUtils.isEMUI3_x() || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
show = Settings.System.getInt(context.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0);
show = Settings.System.getInt(mAppContext.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0);
} else {
show = Settings.Global.getInt(context.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0);
show = Settings.Global.getInt(mAppContext.getContentResolver(), IMMERSION_EMUI_NAVIGATION_BAR_HIDE_SHOW, 0);
}
}
for (OnNavigationBarListener onNavigationBarListener : mListeners) {
Expand Down