0

Hello I am making boxing countdown timer. And I am using ring tha inform me when round starts and end. And I would like to make "end" button with dialog "are you sure want to quit" and after click yes I would like to go to previously activity. And my problem is that I go after for example first round to previous activity but eariel I set for example 4 round I can hear in the background rings while I am on my previous activity. What should I do if I wanna end all task after click "yes"? Hope I add every important informations.

Code from my countdown

timerodprzerwy = new CountDownTimer(dłprzerwy, 1000) {
    @Override
    public void onTick(long millisUntilFinished) {
        mTimeLeftInMillis = millisUntilFinished;
        updatetext2();
    }

    @Override
    public void onFinish() {
        MediaPlayer r2 = MediaPlayer.create(Main3Activity.this, R.raw.rinnkr);
        r2.start();
        tv6.setText("");
    }
}.start();

and code from my dialog:

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();
    }
});
Sergey Glotov
  • 20,200
  • 11
  • 84
  • 98
Jokerino
  • 31
  • 4
  • [MediaPlayer#stop()](https://developer.android.com/reference/android/media/MediaPlayer#stop()) – m0skit0 Jan 28 '21 at 09:03
  • #? If you mean MediaPlayer.stop(); I can't do this in my code – Jokerino Jan 28 '21 at 09:07
  • You could try [CountDownTimer#cancel()](https://developer.android.com/reference/android/os/CountDownTimer#cancel()) as explained in the following post https://stackoverflow.com/a/40203853/6162452 since the counter is probably still running in the background – Jacktraror Jan 28 '21 at 12:15
  • Instance methods are referenced with #, not ., check the docs. Why you can't do that? – m0skit0 Jan 28 '21 at 14:57

0 Answers0