I have an activity which runs a thread and also on that activity in the onBackPressed() void I have an AlertDialog which closes the activity. The problem is that the thread is running after the activity was closed.
new Thread((new Runnable() {
@Override
public void run() {
//...
}
})).start();
@Override
public void onBackPressed(){
new AlertDialog.Builder(this)
.setTitle("Quit")
.setMessage("Are you sure you want to quit?")
.setNegativeButton("No", null)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent intent = new Intent(rest.this, MainActivity.class);
finish();
Thread.currentThread().interrupt();
}
}).create().show();
}