onBack() function in BehaviourDelegate

Former Member
Former Member
Hello,


i have a question on the onBack() function.
For Example when i use the ProgressBar provided by connect IQ.

Is there a way to lock the onBack() function while the ProgressBar is running.
I have a progress running in the background that updates the ProgressBar.setProgress(...) function.

When the progress is finished, i use WatchUi.popView(...) to close the ProgressBar.

As soon as i hit the Back button on the watch it jumps to the underlying View, the progress still goes on.

Now when the progress finishes it hits WatchUi.popView(...) and closes the application as the Initial View was lying unter the Progress Bar on the Stack.

Can i avoid the onBack() to jump back while ProgressBar is on?

I tried to overwrite it with return false and return true but nothing changed.


Of course i can make a variable that tells if the ProgessBar is on or not an prevent the popView to trigger, but i would like to know if i can overwrite the behaviour of
???????the onBack() function.


Any suggestions?


Thanks in advice.

Mike


  • From a design perspective, the progress bar is just an indicator to show the user that some long-running process is happening. The progress bar itself isn't where the long-running processing should be done, that should be happening somewhere else.

    No matter... Is there some reason that you don't want to allow the user to cancel the requested operation? At the very least, make the user interface look like the operation was cancelled cleanly? You should be able to do so with something like this.

    class ProgressViewDelegate extends Ui.BehaviorDelegate
    {
    hidden var _process;

    function initialize(process) {
    BehaviorDelegate.initialize();
    _process = process;
    }

    function onBack() {
    _process.cancelOperation();
    return true;
    }
    }

    class ProgressView extends Ui.ProgressBar
    {
    hidden function _operationCancelled;

    function initialize() {
    ProgressBar.initialize("Processing...", null);
    _operationCancelled = false;
    }

    function cancelOperation() {
    _operationCancelled = true;
    }

    function calledWhenWorkIsDone() {
    if (!_operationCancelled) {
    WatchUi.popView(WatchUi.SLIDE_IMMEDIATE);
    }
    }
    }

    // create the progress bar and delegate
    var progressBar = new ProgressView();
    var progressBarDelegate = new ProgressViewDelegate(progressBar);


  • Former Member
    Former Member over 6 years ago
    Thanks Travis for the response.

    The reason is, that i want to make a sequence of measurements and don't want the user to interrupt (about 2 minutes per measurement). However now i wrote it that the process still goes on and the ProgressBar is just an indicator for the User, if the user pushed the Back key, the ProgressBar disappears but measurement is still going.

    I'll anyway give your code a try.

    Thanks!
  • Another option might be instead of using ProgressBar is just draw your own progress bar on the main view, and then in the delegate for that, handle onBack() as needed. If it's not allowed while processing, return true for example.