Switch positon changing

There are two ways Switch position can be changed in my app

  1. Depending on the value of variable, it is changed its position by using

  2. User can also toggle the switch and below function will be called.
    But now the problem is when switch position is changed itself by variable values, then method 2 is also called. Is there any way to implement method 2 only when user toggle the switch

Don't use switches.

Use button text.

Set a variable that indicates that the switch has been changed programmatically, then test for this in the switch changed event.