How to stop displaying message from Toast when Application is closed?

前端 未结 5 1362
自闭症患者
自闭症患者 2020-12-05 20:26

This is my sample code:

public class MainActivity extends Activity {

    Button buttonClick;
    @Override
    protected void onCreate(Bundle savedInstanceS         


        
5条回答
  •  忘掉有多难
    2020-12-05 21:02

    I want if the application is closed then Toast should also stop displaying the message.

    In your case call cancel() to Toast object to cancel it within onDestroy() method.

    Here is a similar example.

    Updated!

    I tested OP solution but no result.

    .hide() and .cancel() method is available for Toast but seem they are not working. The solution is, you have to create your own custom view which acts like a Toast and then you can cancel all Toasts when the Activity finishes.

提交回复
热议问题