Skip to content
Advertisement

Data doubles every time when i press the button

I print the milliseconds on the screen in hours, minutes, seconds. However, when I press the button, it doubles the data received with each click. For example; When 5 minutes and 10 seconds of data comes in, when I click the button again, the data appears as 10 minutes and 20 seconds. The data is multiplied by 2 each time we click the button. How can i fix that?

JavaScript

Advertisement

Answer

migrate these variables

JavaScript

to local ones by adding long before each

JavaScript

don’t keep them class available (declared on top of file above moethods), as they accumulate on each onDataChange call

btw. asd or fseconds aren’t best variable names…

edit: if you want to store these values in class to be available for other methods then just copy them to class-available variables

JavaScript

in other methods use Global variables

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement