Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
88 views
in Technique[技术] by (71.8m points)

java - How to end tasks which works in background

Hello I am making boxing countdown timer and I have the ring that plays at the end and start of each round. I would like to make "end" button but when I am using Intent like bellow I go to previously activity but mp3 files still working in background. How to end all tasks and go to previously activity without any mp3 and tasks in background?

 btn1.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
            AlertDialog.Builder  dialog=new AlertDialog.Builder(Main3Activity.this);
            dialog.setMessage("Czy napewno chcesz wyj?? z trenignu?");
            dialog.setPositiveButton("Tak", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                    Intent intent=new Intent(Main3Activity.this, Main5Activity.class);
                    startActivity(intent);



                }
            });

            dialog.setNegativeButton("Nie", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });
            AlertDialog dialogg=dialog.create();
            dialogg.show();
        }
    });`
           
question from:https://stackoverflow.com/questions/65882740/how-to-end-tasks-which-works-in-background

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

removeEventListener()

use HTML DOM removeEventListener() Method

btn1.removeEventListener("click", function(){});

see: https://www.w3schools.com/JSREF/met_element_removeeventlistener.asp


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...