Action in SnackBar called instantly when show
I'm trying to show my SnackBar but my action is being called instantly when shown and not when the button is clicked. Why is this happening?
fun showSnackBar(msg
String,btnMsgString,action:Unit){
SnackBar.make(binding.root,msg,Snackbar.LENGTH_SHORT)
.setAction(btnMsg){
action
}
}.show()
And thats what I do when calling this method:
showSnackBar("Added","Undo",undoAction())
fun undoAction(){
//here I delete an item from a list
}