0
handler.postDelayed(new Runnable() {
            public void run() {
                if (MainTab.isRunning == true)
                    ;
                {
                    Dialog.show();
                }
            }
        }, Sec * 1000);

isRunning is a variable and in my activity whenever it calls onStop or onPause method it becomes false. However it's not working, even if I close my app Dialog still wants to add a window and I'm getting errors.

Kara
  • 6,115
  • 16
  • 50
  • 57
Janek
  • 101
  • 1
  • 1
  • 13

2 Answers2

1

Remove the extra ;:

handler.postDelayed(new Runnable() {
            public void run() {
                if (MainTab.isRunning == true)
                {
                    Dialog.show();
                }
            }
        }, Sec * 1000);

It causes your if statement to become useless, as it instructs java to interpret the next line as a new instruction, instead of as a part of the if statement.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

Your callback will still execute even though it does nothing now, this is unnecessary. You should just cancel the callback with removeCallbacksAndMessages() in onPause():

handler.removeCallbacksAndMessages(null);

Or save a reference to your runnable and call handler.removeCallback(runnable).

Sam
  • 86,580
  • 20
  • 181
  • 179