Announcement

Collapse
No announcement yet.

switchToView pushing but not popping

Collapse
X
  • Time
  • Show
Clear All
new posts

  • switchToView pushing but not popping

    Hello,

    I've implemented a View that simply shows a message on the screen (class below). I pop an instance of this view onto the stack. The message shown instructs the user to login via the Garmin Connect mobile phone app (it's part of the oauth flow). After the user has logged in, I call Ui.switchToView as follows:

    Code:
    Ui.switchToView(progressBar, null, Ui.SLIDE_IMMEDIATE);
    Then, when some background work is complete, I call another Ui.switchToView, this time with another simple message view. My problem is that when I hit "back" on this final message view, it takes me back to the message instructing the user to login via the Garmin Connect mobile phone app. I thought that the switchToView where the "login via garmin connect" view was replaced with the progress bar should have removed that message from the stack?

    What am I doing wrong? Thanks in advance!

  • #2
    Message View code is below:


    Code:
    class MessageView extends Ui.View {
    
        var message = "Hello World";
        var messageText;
    
        function initialize(msg) {
            message = msg;
    
            View.initialize();
        }
    
        function setMessage(msg) {
            message = msg;
        }
    
        function onLayout(dc) {
            Util.log("layout: " + message);
            setLayout(dc);
        }
    
        function onShow() {     
            Util.log("show: " + message);
    
            View.onShow();
    
            messageText = new WatchUi.Text({
                :text=>message,
                :color=>Graphics.COLOR_WHITE,
                :font=>Graphics.FONT_SMALL,
                :locX =>WatchUi.LAYOUT_HALIGN_CENTER,
                :locY=>WatchUi.LAYOUT_VALIGN_CENTER
            });        
        }
    
        function onUpdate(dc) {
            View.onUpdate(dc);
    
            Util.log("update: " + message);
            dc.clear();
            messageText.draw(dc);
        }
    
        function onHide() {
            Util.log("hide: " + message);
            View.onHide();
        }
    
    }

    Comment


    • #3
      Update: I've isolated the problem to calling switchToView from the MessageView to a ProgressBar. Switching from a MessageView to a MessageView works, and from a ProgressBar to a ProgressBar works, but when switching from the MessageView to the ProgressBar the MessageView isn't popped from the stack.

      Is this a bug or am I doing something wrong?

      Comment


      • #4
        It is a known limitation. The native views (Menu, Menu2, NumberPicker, Picker, ProgressBar, TextPicker, ..) can't be used with switchToView(). You have to use pushView()/popView().

        There is a brief bit of text on this in the description for switchToView(), which you can see here.

        In my opinion, this is one of the more frustrating inconsistencies in the API. It is something that we know about and are hoping to address in the future.

        Travis
        Last edited by Travis.ConnectIQ; 11-11-2018, 10:47 PM. Reason: Remove bogus %22 from head of link.

        Comment


        • #5
          Originally posted by Travis.ConnectIQ View Post
          I
          There is a brief bit of text on this in the description for switchToView(), which you can see here.

          Travis
          You might want to check that link. It goes nowhere for me.
          raceQs sailboat racing app.

          Comment


          • #6
            You'll also see it in the api doc that comes with the SDK ("Connect IQ>Documentation" in Eclipse)
            My Connect IQ Apps in the Store
            Facebook - Instagram -
            Twitter

            Comment


            • #7
              But the switchToView works when switching from ProgressBar to ProgressBar (i.e. between two native views) -- at least on my FR935 it works. It definitely doesn't support switching from a user view to native view, though. Am I safe to use it for native-to-native, or should I avoid it altogether for native switching?

              Thanks!

              Comment


              • #8
                My gut says, that even if it works for you today on the 935 and the current FW, go by the doc, as it may break on other devices or with a FW update.

                Like Travis said - look at pushView and popView.
                My Connect IQ Apps in the Store
                Facebook - Instagram -
                Twitter

                Comment


                • #9
                  Fair enough. The only problem is that pop+push don't make for as smooth of a UI transition as switchTo. But, if it's not supported it's not supported.

                  Thanks!

                  Comment


                  • #10
                    Yes, using push/pop isn't ideal because the transition is not clean, but it is what we have to work with. Using switchToView() may happen to work in some cases, but I would not rely on it. We don't do any testing to verify it, and it is possible you'd see differences in behavior between devices from different families.

                    Travis

                    Comment

                    Working...
                    X