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
Posts: 32
Registered: ‎02-12-2013
My Device: Playbook

All background threads get suspended after several seconds

[ Edited ]

Hi there,

I have a strange problem with my app:

The app runs the main UI thread, as well as 4 additional background threads (network I/O operations)

 

When I compile and run throught the IDE using USB cable, those threads are working without any problems.

When I create a BAR package using the same code, deploy and run it, those threads get suspended if I put the app in background (say after 30 seconds).

 

I've read about Neutrino's scheduling and thread priorities and then I set all my four threads to have the maximum possible thread priority allowed for a non-root process (63), i.e. for each of them I specify at the beginning:

pthread_setschedprio(pthread_self(), 63);

but the problem still persists.

 

Summary:

The threads are suspended if the app is deployed as a release BAR and its window is in background.

The threads are running ok if the app is in foreground/thumbnails _OR_ simply ran from the IDE (in that case, even in background mode the threads are running).

 

Probably, increasing the threads prio to above 63 will solve the issue, but that would require root permissions and this is not a valid option for our company. 

 

 

Anyone that has a clue about how I can achive a non-suspendable threads without root permission, please give me a hint :smileyhappy:

 

EDIT: Forgot to mention, if I bring back the app from backgrounded to foregrounded state, the threads are neatly resuming and everything runs again flawlessly - therefore this is probably not a deadlock issue

Developer
Posts: 1,280
Registered: ‎03-03-2011
My Device: Playbook, Z10, Q10, Z30 with Files & Folders and Orbit of course

Re: All background threads get suspended after several seconds

Do you have the correct permission set?

 

<permission>run_when_backgrounded</permission>

 

Files & Folders, the unified file & cloud manager for PlayBook and BB10 with SkyDrive, SugarSync, Box, Dropbox, Google Drive, Google Docs. Free 3-day trial! - Jon Webb - Innovatology - Utrecht, Netherlands
Contributor
Posts: 32
Registered: ‎02-12-2013
My Device: Playbook

Re: All background threads get suspended after several seconds

Thank you so much, Innovatology, for this hint! That was indeed the problem..... ..........

 

Now everything works, EXCEPT this   :No:

I am reading the accelerometer in a background thread like this:

const QAccelerometerReading* ar = accelerometer.reading();
qreal dx = ar->x();
qreal dy = ar->y();
qreal dz = ar->z();

 when backgrounded, I always get dx = dy = dz = 0 regardless that I am shaking the device quite much.

Is it the problem with the accelerometer this time?

 

Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: All background threads get suspended after several seconds

Very likely there is either an API for you to request that the sensor keep working even in the background (possibly or possibly just "when in standby"), or that particular sensor cannot be used under those conditions. I know the camera, for example, is tied to the standby state so that it powers down even if you have that background permission set, but I don't know about all the other sensors. Check the rest of the API you're using to see if there's such a thing.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
Posts: 671
Registered: ‎03-21-2012
My Device: BlackBerry PlayBook 16GB

Re: All background threads get suspended after several seconds

For cascades:

 

Running in the background
By default, an application stops receiving sensor readings once an application is running in the background or the screen is locked. However, it's possible to override this behavior by using the QSensor::alwaysOn property. When set to true, the sensor will continue to send reading updates to the application, even if the application is inactive. In order to use this property, the run_when_backgrounded setting must be enabled in the application's bar-descriptor.xml file.

 

For native c/c++

 

To conserve battery power, the sensor can be automatically disabled when the device is in standby mode. However, if there is a need to receive sensor events when the screen is off, you can call sensor_set_background() with enable set to true. However, it is important to consider power consumption when using background mode, as it does use additional battery power.