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

Android™ Runtime Development

Reply
ryh
New Contributor
Posts: 4
Registered: ‎10-14-2013
My Device: Z10 STL100-2 10.1.0.4181 (Developer)
Accepted Solution

Background App stops when screen turns off

[ Edited ]

I have written an Android app with a Service which constantly receives events from the LocationService and the Accelerometer, and am now trying to port it to BlackBerry 10. Testing on a Z10 STL100-2 10.1.0.4181

 

Once the Device hasn't moved for some time, the location listener is unregistered, in order to save energy, and re-registered when moving again.

Don't worry, all this can be deactivated via the visible Activity. But it should resume with the last state (on/off) after reboot.

 

I even magically figured out how to add extra permissions to the BAR manifest: '_sys_android_autostart_service' and 'run_when_backgrounded'.

But, as soon as the screen turns off, my app stops working. No location or accelerometer event being received. Turn the screen on again, everything back to normal.

There is supposed to be an issue regarding the accelerometer, but I could not find it in the tracker.

 

So my questions are:

- Is there any way for an Android port to keep receiving location events when the screen is off?

- Is there any way for an Android port to keep receiving accelerometer events when the screen is off?

- Will my service keep running if more than 8 Apps have been started after mine? (And the user did not hit the close button)

- Would the 'headless' mode in 10.2 help me? (I can currently only test with 10.1, because my carrier has not unlocked 10.2, yet)

- Finally, would this be possible with a native app? (I could port the iOS-port... lot's of fun...)

 

Thank you for your help!

 

PS: If it is of any interest: I am using the Eclipse/ADT plugin V1.6.1 to package and install the BAR.

Retired
Posts: 264
Registered: ‎01-08-2013
My Device: BlackBerry 10 Dev Alpha B

Re: Background App stops when screen turns off

Hey ryh,

 

Referencing our Unsupported Software Features for Android on BlackBerry 10, you can see that background services are not fully supported. This should answer your first two questions.

 

For the third, since the system is restricted to running a maximum of 8 applications, your app, along with the activities/services it creates, may be dismissed and destroyed at that point.

 

'Headless' apps is a term denoted to services for native applications only. As such, most of your troubles could be resolved by writing for native/Cascades instead.

 

Hope this helps! :smileyhappy:

 

    Justin

Justin Jasmann | Android Application Development Consultant
Developer Relations
developer.blackberry.com
ryh
New Contributor
Posts: 4
Registered: ‎10-14-2013
My Device: Z10 STL100-2 10.1.0.4181 (Developer)

Re: Background App stops when screen turns off

[ Edited ]

Hi Justin,

 

So just to be sure: a native Cascades App is the only way to get constant location tracking in the background for BlackBerry 10? No other possibility there or planned?

 

Thank you!

BlackBerry Development Advisor
Posts: 130
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Background App stops when screen turns off

[ Edited ]

As reported here as well (and I'm sure in other spots)

 

http://supportforums.blackberry.com/t5/Android-Runtime-Development/Accelerometer-turns-off-when-scre...

 

I'm working on a addressing it in the next release, similar to what we do with location requests (that is, we enable background mode if your app acquires a partial wake lock).

 

Edit:

 

So my questions are:

- Is there any way for an Android port to keep receiving location events when the screen is off?

 

(Yes,  but you must hold a wake lock).

 

- Is there any way for an Android port to keep receiving accelerometer events when the screen is off?

 

(At the moment, no, but I will change this so it behaves like location.  Note, this may have used to work on older revisions of the software up until the native sensors team added a sensor background mode that is disabled by default and must be explicitly enabled).

 

- Will my service keep running if more than 8 Apps have been started after mine? (And the user did not hit the close button)

 

(There are many thing that factor whether your Services gets to run or not, which is not limited to but includes # of apps already running and memory state of the device).

 

- Would the 'headless' mode in 10.2 help me? (I can currently only test with 10.1, because my carrier has not unlocked 10.2, yet)

 

(No, this is a native thing.  Your app is already technically headless)

ryh
New Contributor
Posts: 4
Registered: ‎10-14-2013
My Device: Z10 STL100-2 10.1.0.4181 (Developer)

Re: Background App stops when screen turns off

[ Edited ]

Thank you very much for your post!

 

Just a couple of last questions to clarify things:

 

Do I understand it correctly that location and accelerometer updates with a device in standby (screen off etc.) are possible _without_ a partial wake lock if I had a native app instead of an android port?

This should save a lot of power!? Even more so because Your sensors framework is more leaned towards saving power than android's.

 

A native headless app would keep running in more situations (eg. more than 8 apps running) than an android port with a partial wake lock and the run_when_backgrounded permission?

Because in a quick test my android port with run_when_backgrounded is killed after I opened the 9th app. Which, as I understand it, headless native apps are not.

 

Are there any extensions to the triggers of triggered headless apps planned? I, for example, would be interested in something like "device_has_moved", based on accelerometer; "has_moved_more_than_x_meters", based on GPS; and "has_turned_more_than_x_degrees", based on GPS.

 

You don't happen to know how to detect at runtime if my android app is running on a blackberry device?

 

Thank You and regards.

BlackBerry Development Advisor
Posts: 130
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Background App stops when screen turns off

Location and sensor updates are possible when the device goes into standby for native apps, but it needs to be explicitly enabled / disabled.  I agree, it's nicer than how Android handles it. :smileyhappy:


run_when_backgrounded doesn't affect Android applications, but you're right, it's likely your app does get trimmed after the 9th is opened, and there's some future work going in to address this so it can keep running (as well as future work so your app can be started on boot).

 

I'm not at all connected or familiar with how triggers are evolving, so that question is probably better suited in the native forum.

 

 

ryh
New Contributor
Posts: 4
Registered: ‎10-14-2013
My Device: Z10 STL100-2 10.1.0.4181 (Developer)

Re: Background App stops when screen turns off

All right.

 

Thank you again :Genius: