Skip to content

修复Handler引发内存泄露 #23

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

Open
wants to merge 1 commit 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
23 changes: 18 additions & 5 deletions app/src/main/java/sample/kingja/loadsir/PostUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.kingja.loadsir.callback.Callback;
import com.kingja.loadsir.core.LoadService;

import java.lang.ref.WeakReference;

/**
* Description:TODO
* Create Time:2017/9/4 15:21
Expand All @@ -28,11 +30,22 @@ public static void postSuccessDelayed(final LoadService loadService) {
}

public static void postSuccessDelayed(final LoadService loadService, long delay) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
loadService.showSuccess();
new Handler().postDelayed(new SuccessRunnable(loadService), delay);
}

private static class SuccessRunnable implements Runnable {

private WeakReference<LoadService> mLoadService;

public SuccessRunnable(LoadService loadService) {
mLoadService = new WeakReference<LoadService>(loadService);
}

@Override
public void run() {
if (mLoadService.get() != null) {
mLoadService.get().showSuccess();
}
}, delay);
}
}
}