Skip to content

Instantly share code, notes, and snippets.

@methodin
Created April 30, 2011 17:42
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save methodin/949830 to your computer and use it in GitHub Desktop.
Toast handler for Android (avoids contextual errors)
// Need a handler for toast
public void makeToast(String str) {
Message status = toaster.obtainMessage();
Bundle datax = new Bundle();
datax.putString("msg", str);
status.setData(datax);
toaster.sendMessage(status);
}
public Handler toaster = new Handler(){
@Override
public void handleMessage(Message msg) {
Toast.makeText(getBaseContext(), msg.getData().getString("msg"), Toast.LENGTH_SHORT).show();
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment