Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
SammyBGoode
Posts: 22
Registered: ‎11-12-2012
My Device: Bold 9900

Animation delay - unexpected behaviour. Insight into execution issues

[ Edited ]

This was a funny one.  An animation (translate transition, if it matters, and I don't think it does) appears to have been prevented from running by resource-intensive system calls.  This is unexpected behaviour.  I found a work-around, and note it here as feedback to the company and other readers.

 

A snippet:

 
 

void MyControl::onTouch(TouchEvent *p)
{
    // .......
    mAnimation->play();
    emit mySignal();
    // ......
}

//....... 

void MyApp::onMySignal()

{
    //....
    turnOffCamera();
    turnOnCamera();
    // .....
}

 The unexpected behaviour is as follows: the animation's state does not transition from "started" to "playing" until after control returns from onMySignal().  Which is to say, the animation doesn't start playing until the calls to the camera library finish.  This takes a second or two.

 

I had thought that animations ran asynchronously "in the background" and would not be effected by onerous subsequent calls in the sequence.

 

Interestingly, if I put a sleep() call right after calling play() it makes no difference.  Also, if I put a blocking call right after calling play that only releases when the animator's state transitions to playing, the program blocks forever.

 

This told me that the state would not flip from started to playing until control returned to some event pump upstairs.

 

Here is my work-around: instead of doing the heavy lifting of turning on and off the camera in the signal handler, I launch a one shot timer with a callback that does this heavy lifting.  In this way, control returns immediately.

 

void MyApp::onMySignal()
{
    //....
    QTimer::singleShot(50, this, heavyLifting());
    // .....
}

 
void MyApp::heavyLifting()
{
    //....
    turnOffCamera();
    turnOnCamera();
    // .....
}

 

 ----------

 

And this works.  The camera turns off while the animaiton plays.

 

If this *is* intended behaviour, may I ask that the documentaiton provide more clarity vis a vis how an animation is executed. 

 

Thanks --SbG.