Skip to content

Instantly share code, notes, and snippets.

@wutianlong
Last active June 2, 2016 09:13
Show Gist options
  • Save wutianlong/6a817a8c196a40320df0 to your computer and use it in GitHub Desktop.
Save wutianlong/6a817a8c196a40320df0 to your computer and use it in GitHub Desktop.
Handler-Optimized
private WeakReference<ClassName> mActivityWeakReference = new WeakReference<ClassName>(this);
private final Handler mHandler = new InnerHandler(mActivityWeakReference);
private static class InnerHandler extends Handler {
WeakReference<ClassName> activityWeakReference;
InnerHandler(WeakReference<ClassName> activityWeakReference) {
this.activityWeakReference = activityWeakReference;
}
public void handleMessage(android.os.Message msg) {
if (activityWeakReference.get()!=null){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment