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
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Running app while in standby mode

Battery Guru's written in AIR, so no I didn't have to do that.

I'm pretty sure you don't have to do that however.

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!
Please use plain text.
Developer
rmisk
Posts: 64
Registered: ‎02-21-2012
My Device: Blackberry Playbook
My Carrier: None

Re: Running app while in standby mode

I don't think I should either however when in GeolocationSampleManaged I use the following snippet:

 

bps_initialize();

/*
* Initialize the screen so that the window group Id is properly set, to allow
* the dialogs to be displayed.
*/
if (setup_screen() != EXIT_SUCCESS) {
fprintf(stderr, "Unable to initialize screen.");
exit(0);
}
int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
int rc;
rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_IDLE_MODE, &idle_mode);
if (rc != 0)
{
fprintf(stderr, "Screen error setting SCREEN_IDLE_MODE_KEEP_AWAKE: %d\n", rc);
// return EXIT_FAILURE;
}

 

it doesn't work.

 

But if I put it:

 

while (!exit_application) {
/*
* Using a negative timeout (-1) in the call to bps_get_event(...)
* ensures that we don't busy wait by blocking until an event is
* available.
*/
int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
int rc;
rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_IDLE_MODE, &idle_mode);
if (rc != 0)
{
fprintf(stderr, "Screen error setting SCREEN_IDLE_MODE_KEEP_AWAKE: %d\n", rc);
// return EXIT_FAILURE;
}

 

It seems that I must put it in the main loop for it to work.

 

Do you think it is a bug?

 

Please use plain text.
Developer
Neurocode
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: Running app while in standby mode

Hi rmisk,

 

This:

 

int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;

screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_IDLE_MODE, &idle_mode);

 

worked once or twice after I restarted the Playbook.

 

I had assumed that all I needed to do was include that once near the beginning of the code but I found it works reliably (so far) if I put in the main loop so that it is constantly executed/refreshed.

 

This isn't what I expected.  Is there any documentation saying how it works and where it should be implemented?

When you make the initial call outside of main, do you call it after you have registered for events and rendered some initial graphic to the screen?

 

I have noticed that when registering for screen events, none are received until something is rendered to the screen and I would therefore assume that setting SCREEN_IDLE_MODE_KEEP_AWAKE would also only work once something is rendered to the screen.

 

The apps I am developing at the moment all render something to the screen outside of the main loop just to get the screen events flowing.  In some cases this is just a blank (black) screen.

 

I havn't tested it but i would assume calling SCREEN_IDLE_MODE_KEEP_AWAKE after an initial setup (and display of graphic) and then after receiving each NAVIGATOR_WINDOW_ACTIVE event (and after you have rendered your next frame) should keep your app awake.

 

Just a thought.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Please use plain text.
Developer
rmisk
Posts: 64
Registered: ‎02-21-2012
My Device: Blackberry Playbook
My Carrier: None

Re: Running app while in standby mode

Hi Dan,

 

Thanks for your reply.  If I understand you correctly I think I am essentially doing that.  My previous posting might be a little confusing/inaccurate.  I meant something like:

 

main()

 

STAY_AWAKE code ...(1)

 

while (!EXIT)

{

STAY_AWAKE code ...(2)

Process and update screen

}

do

 

(1) doesn't work

(2) I think this does what you recommend  ???

(2) worked in an app based on geolocation

(2) didn't work on an app based on helloworld(Display)  ... I get no errors any where still doesn't work and I don't really know how to trouble shoot.

 

Roger

Please use plain text.
Developer
Neurocode
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: Running app while in standby mode

Hi Roger,

 

I have done some testing and have got it to work.  This is how I have attempted it in my code.

 

main()

 

// initialisation stuff

 

Render a single frame to the screen (usually black, unless displaying a splash/loading screen)

 

STAY_AWAKE code

 

while(!Exit)

{

bool bStayAwake;

process and update screen // when window active/Full screen events are triggered set bStayAwake to true;

if (bStayAwake)

{

STAY_AWAKE code

}

}

 

As i mentioned before, the key thing here is to render to the screen before calling the stay awake code.

 

Hope this helps.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 660
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Running app while in standby mode

Okay,

I just added the following code to the bbutil_init_egl() function in the HelloWorldDisplay example, immediately following the call to screen_create_window().

 

    int idle_mode = SCREEN_IDLE_MODE_KEEP_AWAKE;
rc = screen_set_window_property_iv(screen_win, SCREEN_PROPERTY_IDLE_MODE, &idle_mode); if (rc) { perror("screen_set_window_property_iv(SCREEN_PROPERTY_IDLE_MODE)"); bbutil_terminate(); return EXIT_FAILURE; }

 

The app stays on the screen indefinitely and the device does not go to sleep when this app is visible.  This is the same thing that the camera does when you start recording video to ensure the device does not go to sleep.  I am not sure what you are doing differently.  You do not need to render anything to the screen prior to setting SCREEN_PROPERTY_IDLE_MODE, all you need is a window handle.  The key here though is that the window needs to be visible on screen in order for this property to have any effect.

 

Cheers,

Sean

Please use plain text.
Developer
Neurocode
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: Running app while in standby mode

On completing some further testing I found that you only need to set the screen window property once.  I tested a program that was essentially the following:

 

main ()

 

// Init code

 

// Render black screen to device

 

// Set Keep awake flag

 

bool bPause = false;

while(!Exit)

{

// process app logic and events

 

if (!bPause) // gets set to true if screen inactive event received

      draw();

}

 

Using this i found that my app would not go into Standby, even if I swap to other applications and then return.

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Please use plain text.
Developer
Neurocode
Posts: 43
Registered: ‎12-16-2011
My Device: Torch 9800 & Playbook
My Carrier: Three

Re: Running app while in standby mode

Hi sean,

 

I am not using bbutil, but had the same result as you.

 

Indeed I should have tested before jumping to conclusions.  I tested my code above and commented out the initial drawing of a frame before the main loop.  This still resulted in an app that did not enter standby.

 

 

regards

Daniel - Neurocode
If my posts help, please click the Like button.

gymChronicles - helping you to keep motivated
Please use plain text.
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Running app while in standby mode

I think there may be several things getting conflated in this discussion though. The "Keep Awake" feature prevents the tablet from entering standby (and turning off the screen). This isn't directly related to whether an app is able to keep running when it's been made "inactive" or the tablet enters standby.

The details haven't been fully documented yet, so I can't speak with authority on how it works across each environment. I do know that both of my own apps, written in AIR, using one or more APIs to continue processing as needed even when the tablet is in standby (with the screen off). One of them also implements "Keep Awake" (keeping screen on so long as my app is visible) even though it has nothing to do with the other thing.

The NDK shows events to let apps detect their window state, and also their "active/inactive" state, but I haven't yet seen anything specific with respect to either freezing their event loops when in standby, or not freezing them. If one of those two states is the normal condition, I haven't seen an API that is defined as overriding that condition. Using KEEP_AWAKE can have the effect of letting an app stay running, but it's only a *side effect* of the fact that it keeps the screen on and the tablet out of standby.

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!
Please use plain text.
BlackBerry Development Advisor
smcveigh
Posts: 660
Registered: ‎11-29-2011
My Device: developer
My Carrier: other

Re: Running app while in standby mode

Right.  As Peter mentions, the SCREEN_PROPERTY_IDLE_MODE is only used to keep the screen on.  A side-effect of the screen being on is that the device will not go to standby automatically.  The user can still hit the standby button and bypass this.

Nothing forcibly stops your code from continuing to run in standby, however many OS services will become unavailable.  (eg. Sensor readings).  It is a best practise to idle your app when the system is entering standby in order to preserve battery, and this is what the OS is doing underneath your app.

 

Cheers,

Sean

 

Please use plain text.