Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Toast isn't working in listener

I want to open a Toast, but it doesn"t seem to work in a listener (of Smack), like this example:

private ChatManagerListener chatManagerListener = new ChatManagerListener() {

    public void chatCreated(Chat newChat, boolean createdLocally) {
        if(!createdLocally) {

            Toast.makeText(mCtx, "CHAT CREATED", Toast.LENGTH_SHORT).show();

            // do some stuff

        }
    }
}; 

If I use the Toast-code somewhere else in the class, it works, as long as it isn't a listener.

like image 810
user969039 Avatar asked Feb 22 '23 20:02

user969039


1 Answers

runOnUiThread(new Runnable() {  
   @Override  
   public void run() {  
      Toast.makeText(Activity.this, "import finished", Toast.LENGTH_SHORT).show();  
   }  
});
like image 183
Mohammad Ersan Avatar answered Mar 04 '23 23:03

Mohammad Ersan