Skip to content

Instantly share code, notes, and snippets.

@manniru
Created April 20, 2022 14:20
Show Gist options
  • Select an option

  • Save manniru/bba36b61fb4cff82be1aa48d4a2917d4 to your computer and use it in GitHub Desktop.

Select an option

Save manniru/bba36b61fb4cff82be1aa48d4a2917d4 to your computer and use it in GitHub Desktop.
Can't create handler inside thread that has not called Looper.prepare()
JAVA
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
Toast toast = Toast.makeText(mContext, "Something", Toast.LENGTH_SHORT);
toast.show();
}
});
KOTLIN
Handler(Looper.getMainLooper()).post {
Toast.makeText(mContext, "Something", Toast.LENGTH_SHORT).show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment