This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dialog repeating twice

 
Naishadh Parmar
Ranch Hand
Posts: 95
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4181
21
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Naishadh Parmar
Ranch Hand
Posts: 95
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.








 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic