0

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));
2
Contributors
5
Replies
29
Views
5 Years
Discussion Span
Last Post by Stefan_1
0

Do you have a debug or console output/log with the relevant stack trace or error message available for us?

0

look i need to make every second the health to go down by "1" after going the health under 20 or is equal to 20 to show the "alertDialog" i dont have any errors. The problem is after the "Health" passed the border/limit the application is cryshing i dont know why is that happening, is there someone to help me with it ?
I also make sure that there is one time show of the "alertDialog" with boolean but doesnt help...
Thanks in advice :)

Edited by Stefan_1: misstake in post

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.