I made a ProgressDialog for a meditation app. After pressing the Cardview corresponding to the meditation session, a ProgressDialog appears for 3 seconds, and then the other activity opens(m1 activity). But there is one big problem. After returning to MeditationActivity the ProgressDialog shows and never stops.
This is the code I am using:
public class Meditation extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMeditationBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
findViewById(R.id.Med_1).setOnClickListener(v -> {
startActivity(new Intent(getApplicationContext(), m1.class));
progressDialog = new ProgressDialog(Meditation.this);
progressDialog.show();
progressDialog.setContentView(R.layout.loading_screen_first_version);
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
progressDialog.dismiss();
}
}
Some of m1 code:
public class m1 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_m1);
findViewById(R.id.backm).setOnClickListener(v -> {
onBackPressed();
mediaPlayer.stop();
notificationManager.cancelAll();
});