aspose file tools*
The moose likes Android and the fly likes Dialog repeating twice Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Dialog repeating twice" Watch "Dialog repeating twice" New topic
Author

Dialog repeating twice

Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95

I have a dialog in my activity which is inside the onFinish method of a CountDownTimer.
So as soon as the timer finishes it callbacks the onFinish() method, which in turn displays the Dialog.

Now, my problem is, that when I click on the "Yes" button (positive button) of the Dialog, the Dialog shows again. When the "yes" button of this new Dialog is pressed then the function is completed.
But, why is the Dialog occuring again???
My code:

There is no problem in the reset1() method. I have checked it again and again.

Please please please help me out!!!
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95

I have also commented all the lines of code in the positive button onClick() method. So no problem with the lines of code in the "Yes" button method
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

I think you need to provide more info. The problem is likely because the timer gets started twice. This could happen depending on where your timer gets created and started. Remember you are not guaranteed to have just one instance of the activity running at a time. What I have seen - especially when the view is changed from portrait to landscape or back, that you can get different activities created for both cases. Or when the activity gets pushed to the background, then brought forward you may also get a new activity instance.

In these cases, the SavedState Bundle which usually gets passed to onCreate would be non-null. You should check that and determine what to do. You could, for example, override the onSaveState method (I think that's the name) to record when the time should complete into the SavedState bundle. Then kill the timer. Then in the onCreate method, check if the Bundle is null - if it is you know you need to start a new timer. If not, check for the time when the timer should complete, and if present, create a new timer counting down to that same time point. If the saved end-time is not in the bundle, decide something else to do that makes sense.

All that is conjecture, though. You would need to provide a small sample which shows the problem to get anything more than a guess.


Steve
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95


Thanks a lot Steve. My problem was solved.

Actually I had implemented the onResume() method as well and that too, had the cdt.start() method. So the timer was started twice.

I always wonder that the IT industry will always be controlled by the "Steve"s. Steve Jobs(Apple), Steve Wozniak(Apple), Steve Ballmer(Microsoft) and Steve Luke.

Just joking. Thanks a lot.








 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dialog repeating twice