Hello,
I wonder if you can help me with a timer problem? The attached program sometimes works as intended on a real device, but I'd say it does so less than 50% of the time (in either debug or release mode), and it almost always fails to run correctly when I remove the Do While loop (that was inserted for troubleshooting purposes only).
The feature I am having trouble with, i.e., the operation of the "Auto Forward" button (on the only included layout) is supposed to perform as follows:
1) When the app starts, a countdown timer is displayed on the AutoFwd button, and it shows a countdown in action (i.e., 10 ... 9 ... 8 ..., with a new number displaying every second). This feature seems to be working as intended; a future version will include code to start another activity when the countdown reaches 0, but that is irrelevant at this point.
2) When the user holds this button down for MORE than (approximately) 2 seconds, the countdown restarts at 10. This feature also seems to be working as intended.
3) If the user presses and releases the button more quickly (i.e., holds it for LESS than 2 seconds) WHILE THE COUNTDOWN IS IN PROGRESS, "...Timer1" is supposed to stop altogether, with the effect of the countdown stopping altogether (since the number being displayed can only change when Timer1 is actually running). Well, sometimes it does stop and sometimes it does not!
4) If the user presses and releases the button quickly (i.e., holds it for LESS than 2 seconds) WHILE THE COUNTDOWN IS NOT IN PROGRESS (i.e., it is suspended), Timer1 is supposed to start up again and the countdown is supposed to continue (from where it originally stopped). Well, this operation works once in a while, but certainly not all of the time.
My main question has to do with the fact that the code (part of an If-Then statement) that ENABLES Timer1 (very shortly after it had been DISABLED), seems to be getting executed without any action by the user. In particular, although the program seems to correctly detect each button UP event, it also seems to be detecting some "button UP" events that did not actually occur; I say this because I have verified (or at least I think I have) that it is the (...Timer1.enabled = true) code in one of my If-Then statements that is causing Timer1 to restart, even though the user simply pressed the button quickly and let go (one time!) ... and this code should not be running. FYI, Timer2 starts on a button DOWN event, and it stops on a button UP event; and it seems to be working correctly, at that.
To repeat something said above, the (only) Do-While loop is my program was inserted for trouble-shooting purposes only. If the features (3 & 4) described above do not work for you at all, then perhaps they will work for you if you adjust the number in the Do-While loop (to 10000 or 30 or 40000, say?). This loop does essentially nothing except to keep some other lines of code from executing (for a very brief time!), but the question is, why should that loop---or the MsgBox that has been commented out---make any difference whatsoever in whether or not Timer1 actually stops and remains stopped (after a short click)?
As a final point of clarity, I am using the button DOWN and UP events, instead of the CLICK and LONG CLICK events, so that I have better control over the timing of a long click. However, now that I've spent so much time (many, many hours) trying to get this feature to work, it is also a matter of principle; i.e., I'd really like to use the down and up events for this feature, and all that I really want is some (very robust) code to do the job. If you see a definite fix for my code, please let me know. Alternatively, if you can provide me with some altogether different code that definitely does the job, that would be fine too!
Thanks for any words or wisdom, and especially for the code or code corrections that you can send my way!
CoderMaan,
July 15, 2014
I wonder if you can help me with a timer problem? The attached program sometimes works as intended on a real device, but I'd say it does so less than 50% of the time (in either debug or release mode), and it almost always fails to run correctly when I remove the Do While loop (that was inserted for troubleshooting purposes only).
The feature I am having trouble with, i.e., the operation of the "Auto Forward" button (on the only included layout) is supposed to perform as follows:
1) When the app starts, a countdown timer is displayed on the AutoFwd button, and it shows a countdown in action (i.e., 10 ... 9 ... 8 ..., with a new number displaying every second). This feature seems to be working as intended; a future version will include code to start another activity when the countdown reaches 0, but that is irrelevant at this point.
2) When the user holds this button down for MORE than (approximately) 2 seconds, the countdown restarts at 10. This feature also seems to be working as intended.
3) If the user presses and releases the button more quickly (i.e., holds it for LESS than 2 seconds) WHILE THE COUNTDOWN IS IN PROGRESS, "...Timer1" is supposed to stop altogether, with the effect of the countdown stopping altogether (since the number being displayed can only change when Timer1 is actually running). Well, sometimes it does stop and sometimes it does not!
4) If the user presses and releases the button quickly (i.e., holds it for LESS than 2 seconds) WHILE THE COUNTDOWN IS NOT IN PROGRESS (i.e., it is suspended), Timer1 is supposed to start up again and the countdown is supposed to continue (from where it originally stopped). Well, this operation works once in a while, but certainly not all of the time.
My main question has to do with the fact that the code (part of an If-Then statement) that ENABLES Timer1 (very shortly after it had been DISABLED), seems to be getting executed without any action by the user. In particular, although the program seems to correctly detect each button UP event, it also seems to be detecting some "button UP" events that did not actually occur; I say this because I have verified (or at least I think I have) that it is the (...Timer1.enabled = true) code in one of my If-Then statements that is causing Timer1 to restart, even though the user simply pressed the button quickly and let go (one time!) ... and this code should not be running. FYI, Timer2 starts on a button DOWN event, and it stops on a button UP event; and it seems to be working correctly, at that.
To repeat something said above, the (only) Do-While loop is my program was inserted for trouble-shooting purposes only. If the features (3 & 4) described above do not work for you at all, then perhaps they will work for you if you adjust the number in the Do-While loop (to 10000 or 30 or 40000, say?). This loop does essentially nothing except to keep some other lines of code from executing (for a very brief time!), but the question is, why should that loop---or the MsgBox that has been commented out---make any difference whatsoever in whether or not Timer1 actually stops and remains stopped (after a short click)?
As a final point of clarity, I am using the button DOWN and UP events, instead of the CLICK and LONG CLICK events, so that I have better control over the timing of a long click. However, now that I've spent so much time (many, many hours) trying to get this feature to work, it is also a matter of principle; i.e., I'd really like to use the down and up events for this feature, and all that I really want is some (very robust) code to do the job. If you see a definite fix for my code, please let me know. Alternatively, if you can provide me with some altogether different code that definitely does the job, that would be fine too!
Thanks for any words or wisdom, and especially for the code or code corrections that you can send my way!
CoderMaan,
July 15, 2014