Skip to content

Instantly share code, notes, and snippets.

@gabu
Created August 9, 2012 23:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabu/3309048 to your computer and use it in GitHub Desktop.
Save gabu/3309048 to your computer and use it in GitHub Desktop.
最近出るようになったLintの警告「This Handler classes should be static or leaks might occur.」を修正したHandlerがこちらになります。 元ネタ: http://stackoverflow.com/a/11408340
private Recipe114Handler mHander;
private static class Recipe114Handler extends Handler {
private final WeakReference<Recipe114Activity> mActivity;
public Recipe114Handler(Recipe114Activity activity) {
mActivity = new WeakReference<Recipe114Activity>(activity);
}
@Override
public void handleMessage(Message msg) {
Recipe114Activity activity = mActivity.get();
if (activity == null)
return;
switch (msg.what) {
case MSG_UPDATED_STATUS:
activity.showToast("つぶやき完了!");
activity.mEditText.setText("");
break;
case MSG_ON_EXCEPTION:
activity.showToast("失敗しました。。。");
break;
}
// 共通でプログレスダイアログは閉じる。
activity.dismissProgressDialog();
}
}
@gabu
Copy link
Author

gabu commented Aug 9, 2012

コンパイルもできない超断片だけどAndroiderなら何となく読めるよね!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment