why my app is crushing after passing the seconds ?
new Timer().schedule(new TimerTask() {
@Override
public void run() {
Health -= 1;
if(Health <= 20) {
if (!canSeeWarnDialog) {
final AlertDialog alertDialog2 = new AlertDialog.Builder(MainActivity.this).create();
alertDialog2.setTitle("Im hungry");
alertDialog2.setMessage("The dog health is going low " +
"\ngive him some food");
alertDialog2.setButton("Got it", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog2.show();
canSeeWarnDialog = true;
return;
}
}
}
}, 0, TimeUnit.SECONDS.toMillis(1));