You can cache the current Toast in the Activity variable, and then cancel it before showing the next toast. Here is an example:
Toast m_currentToast; void showToast(String text) { if(m_currentToast != null) { m_currentToast.cancel(); } m_currentToast = Toast.makeText(this, text, Toast.LENGTH_LONG); m_currentToast.show(); }
Another way to instantly update a Toast message:
void showToast(String text) { if(m_currentToast == null) { m_currentToast = Toast.makeText(this, text, Toast.LENGTH_LONG); } m_currentToast.setText(text); m_currentToast.setDuration(Toast.LENGTH_LONG); m_currentToast.show(); }
inazaruk
source share