Ti.UI.Switch switching to "off" upon resume

You must Login before you can answer or comment on any questions.

I'm developing an iPad app using the latest Mobile SDK version 2.1.3.GA, and when building to iPad on the simulator and on the actual device (I haven't tried on iPhone or Android), my Ti.UI.Switch elements always switch back to the "off" position, no matter what their state was when the app comes back to active after being in the background.

For example, I have a layer switching dialog (a Popover) which allows users to turn things on and off. If they make the popover display that holds the switches, then hit the home button to return to the home screen, then come back into the app, you can watch all the switches that were in the "on" position animate to "off". There is no event fired for the switch event either, it just happens silently.

My current "fix" is to keep track of what the value of the switch should be, and then on capturing the "resume" event from the app, ensuring the switch is flipped to the correct state:

Ti.App.addEventListener('resume', function(){
    if(obj.isOn != obj.sw.getValue()){
        obj.sw.setValue(obj.isOn);
    }
});
I'm thinking this must be a bug unless I haven't seen some configuration parameter that would force this kind of behavior. Does anyone else see this? I haven't been able to find any bugs posted on jira about this, and also I can't see how to post a bug for the Mobile project, just some others that aren't relevant.

— asked 8 months ago by Matt Mendick
2 Comments
  • Hi Matt, though i did not find any scenario like this, but it seems interesting so just want to ensure one thing. You are just putting app in the background by pressing home button? and not killing the app in the background? and result is like this which you described here.

    — commented 8 months ago by Ashish Nigam

  • Ashish, yes, I'm sorry I didn't specify that at first, but yes, I'm putting the app into the background by pressing the home button. This also occurs if the device is allowed to sit idle so that the screen turns off. When you awaken the iPad the same effect occurs. Thanks for your interest!

    — commented 8 months ago by Matt Mendick

1 Answer

How does your app load the window? If you have used the switch.value property then it may be set to refresh the screen on reload and reload that value set? Maybe take out the switch.value property and test again?

— answered 6 months ago by Andy Leavers
answer permalink
1 Comment
  • Thanks for the response, Andy. I'll give that a try when I am able to go back to that.

    — commented 6 months ago by Matt Mendick

Your Answer

Think you can help? Login to answer this question!