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
Regular Contributor
Posts: 84
Registered: ‎01-31-2013
My Device: Simulator !!!
My Carrier: 8608800458

Can't receive Location updates if screen is off !!!

Once user clicks power button to turn off screen, location updates stop even though the activity is still listening for location upates. Then when screen is on again, the updates start back up.

 

This is different than every other Android device in the world.

 

Someone please verify I'm not going crazy.

Regular Contributor
Posts: 84
Registered: ‎01-31-2013
My Device: Simulator !!!
My Carrier: 8608800458

Re: Can't receive Location updates if screen is off !!!

Seriously no replies. Jeez. So nobody wants to get location updates when user clicks power button to turn off screen? No nav apps that allow user to save power by turning off screen?
Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Can't receive Location updates if screen is off !!!

So I'll reply here as well in case you didn't see it in the other thread ...

 

Do you have a PARTIAL_WAKE_LOCK held?

Regular Contributor
Posts: 84
Registered: ‎01-31-2013
My Device: Simulator !!!
My Carrier: 8608800458

Re: Can't receive Location updates if screen is off !!!

I've tried both with and without partial_wake_lock, but I will test it again to be sure.

I do know that a wake lock will affect (in BB10) the methods get called when power button is clicked or screen times out.

What is your info on Partial Wake Locks?
Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Can't receive Location updates if screen is off !!!

[ Edited ]

Android's location manager uses the native geolocation API for its implementation.  By default, all clients using the geolocation API run with background mode disabled (and there's an API to enable it / disable it).

 

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.bps.lib_ref/com.qnx.doc.bps.lib_re...

 

What Android does is it will enable background mode if it detects

 

a) A non-system Android application using the location manager

b) A non-system Android application having a partial wake lock held

 

Otherwise it will disable background mode, and so that's why you may see no updates when the screen goes off.

 

Now, if you hold a partial wake lock and you're not seeing updates, then there's a potential bug.

 

Regular Contributor
Posts: 84
Registered: ‎01-31-2013
My Device: Simulator !!!
My Carrier: 8608800458

Re: Can't receive Location updates if screen is off !!!

Ok, thanks. I will do more testing, however, I'm certainly using the Location Manager (or at least my Activity is registered for location updates), so doesn't that count for case 1)?

I am using a Partial Wake lock as well, but I'll do more testing there since I've been enabling disabling it for another potential BB10 bug.

Note again that none of this is an issue with real Android device. Activity will receive location updates if it is registered for Location Updates, regardless of wake lock status.

Finally the API for background mode that you linked to doesn't pertain to Android app on BB10 right?
Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Can't receive Location updates if screen is off !!!

On a real Android device, you will continue to receive location updates as long as the device doesn't sleep, and you can prevent sleep by acquiring a partial wake lock. There is no background mode for Android's location manager because it's implied via the wake lock semantics.

 

Since we have to use BB10's native location manager to implement Android's location manager, we have to conform to its API.

 

The integration works like this

 

Android App 1 |

Android App 2 |   --- talks to ----> Android Location Manager --- talks to ----> BB10 Location Manager

Android App n |

 

Android apps are clients to Android's location manager, and Android's location manager is a client to the BB10 location manager.

 

What we don't want to do is enable background mode in Android's location manager always, because that has poor battery life implications.  So we use the fact that an app has a wake lock as a hint that we should turn on background mode.

 

Also what is this other potential BB10 bug?

Regular Contributor
Posts: 84
Registered: ‎01-31-2013
My Device: Simulator !!!
My Carrier: 8608800458

Re: Can't receive Location updates if screen is off !!!

Ok, I've been holding SCREEN_DIM_WAKELOCK. I'll switch over to PATIAL_WAKE_LOCK and retest.

Other bug is in JIRA and relates to the fact that onStop is getting called when user clicks the power button to turn off the screen. Other Android devices call onPause only. Actually the exact set of method calls is also effected by whether the app holds the SCREEN_DIM_WAKELOCK or not. If it does hold that lock, the onStop get's called when user unlocks the screen, strangely. Jira is slow now so can't get link, but search for onStop and you will find.

Also what did you mean by "sleep" above? onPause? onStop?, etc.
Retired
Posts: 140
Registered: ‎04-19-2013
My Device: BlackBerry Z10

Re: Can't receive Location updates if screen is off !!!

By sleep I mean the CPU goes to sleep.  If there is no PARTIAL_WAKE_LOCK held, an Android device will eventually enter sleep until there's an interupt that's causes it wake it up.  If you hold a PARTIAL_WAKE_LOCK you indicate to the system that the CPU should not sleep for the duration that the lock is held.

 

Holding PARTIAL_WAKE_LOCKS indefinitely or for long periods of time has severe battery life implications.  You should evaluate how necessary it is to have GPS updates when the user turns the screen off.

 

A SCREEN_BRIGHT_WAKELOCK / SCREEN_DIM_WAKELOCK is not quite the same as a PARTIAL_WAKE_LOCK.  They keep the screen on (to varying degrees, which also has battery life implications), but the user can override it by pressing the power button.  These wake locks as documented do not keep the CPU on and so the device can eventually sleep.

Regular Contributor
Posts: 84
Registered: ‎01-31-2013
My Device: Simulator !!!
My Carrier: 8608800458

Re: Can't receive Location updates if screen is off !!!

Ok, understood. My app is sort of like a Navigation app (except it's for Golf), so it needs to get location updates when screen is off.

Users typically use my app for hrs at a time and are ok with the battery getting used up if it lasts for at least 5 hrs.

On standard android devices I hold a SCREEN_DIM_WAKELOCK only and have never had a problem losing the location updates.

On BB10 the main issue is that when user unlocks the screen, to get back to the app, the location updates start from scratch and GPS satellites have to get re-acquired, thus taking time. Also since updates were not received in background, the 'auto-advance' feature does not work on BB10. I will try with Partial wake lock and see if that resolves it and what the battery life is.

I have over 200,000 users on standard Android devices with my app so I know a bit about this. BB10 definitely behaving differently. I'll update here when I complete some more testing later today.