fenix 3 - back button crashes do to Comm.setMailboxListener

Former Member
Former Member
Hey everyone
In my app i have 2 views and in the second i am using Toybox.Communications .
On the device when i want to go back from the second view to the first view it crashes.
I have noticed that if i comment out this function: Comm.setMailboxListener() from in the second view it doesn't crash anymore.
I believe it's an object that i need to release before leaving the second view i just dont know how and what.
This is the code from the second view:

function initialize()
{
Comm.setMailboxListener( method(:onMail) );
}

//from class that extends Ui.BehaviorDelegate :
function onBack()
{
if( ( session != null ) && session.isRecording() )
{
session.stop();
relatedView.discardRecording();
}
var firstView = new FirstView();
Ui.switchToView(splashView, new FirstViewDelegate(firstView), Ui.SLIDE_IMMEDIATE);
return true;
}


I would appreciate any help,
Thank you!
  • I'm not certain about this, setMailboxListener() call takes a Method object that holds a reference to your View class. When you switch views, if you don't tell the Comm module to release this reference to your view, both views will be kept in memory. This could cause your application to crash due to low memory.

    The following should set the listener when your view appears, and unset it when the view is hidden.

    function initialize() {
    }

    function onShow()
    {
    Comm.setMailboxListener(self.method(:onMail));
    }

    function onHide()
    {
    Comm.setMailboxListener(null);
    }


    Travis