Skip to content

Instantly share code, notes, and snippets.

@laaptu
Last active December 22, 2015 06:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laaptu/6433023 to your computer and use it in GitHub Desktop.
Save laaptu/6433023 to your computer and use it in GitHub Desktop.
Creating static handlers on Android
CustomHandler customHandler = new CustomHandler(this);
customHandler.sendEmptyMessage(0);
static class CustomHandler extends Handler{
private final WeakReference<FriendListFragment> fragmentHolder;
public CustomHandler(FriendListFragment friendListFragment){
fragmentHolder = new WeakReference<FriendListFragment>(friendListFragment);
}
@Override
public void handleMessage(android.os.Message msg) {
final FriendListFragment friendListFragment = fragmentHolder.get();
switch (msg.what) {
case 0:
Toast.makeText(friendListFragment.context,
"Sorry no groups/friends has been added",
Toast.LENGTH_SHORT).show();
if (friendListFragment.mFriendListAdapter != null) {
friendListFragment.mFriendListAdapter.friendList.clear();
friendListFragment.mFriendListAdapter.notifyDataSetChanged();
friendListFragment.fragmentCommunicator.toggleVisibility(View.GONE);
}
break;
default:
break;
}
friendListFragment.showDialog(null);
friendListFragment.resetThreadCancelBoolean();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment