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

Java Development

Reply
Highlighted
Contributor
Posts: 11
Registered: ‎02-26-2010
My Device: Curve 8310 & Curve 8530
My Carrier: 8310 on ATT 8530 on Sprint

GPS Criteria and LocationListener Interface

I've been looking into the Criteria class when instantiating my LocationProvider which in turns registers my LocationListener

 

I've read this article:

 

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800703/What_Is...

 

and understand some more about the implementation.

 

I was curious if its a good practice to have two different criteria objects. One for when the GPS is fixed adn working properly and the other for when the application is waiting for the fix to come back.

 

I am currently looking :

 

location.isValid() 

 

and 

 

public void providerStateChanged(final LocationProvider provider, final int newState)

 

methods for when the state changes.

 

When i detect a negative GPS state between those two i reset my locationlistener to a higher interval.

 

Should i also incorporate the above idea with two Criteria classes?

 

Is this a "Best Practice"?

 

I want to perserve the battery life but still run for long periods of time (hours)

 

---------------------------------------------------------------------------------------------------------------

My current development environment:

Eclipse 3.4

BlackBerry JDE Plug-in For Eclpise 1.0.0.67

Blackberry JDE Component Package 4.2.1.17

Blackberry JDE Component Package 4.3.0.16

Blackberry JDE Component Package 4.5.0.16

Blackberry JDE Component Package 4.6.1.27

Blackberry JDE Component Package 4.7.0.46

WIndow XP SP 3

Developer
Posts: 587
Registered: ‎01-19-2010
My Device: BOLD 9700 OS5.0.0.x on Rogers Canada
My Carrier: Rogers

Re: GPS Criteria and LocationListener Interface

If you believe the secondary criteria will allow you to KEEP a tentative GPS fix, then by all means go ahead, but if your secondary criteria is just a placeholder to do nothing while searching for a GPS fix, then I would suggest against it. I think a better plan would be to have a flag to denote whether or not you have a GPS fix, and have your location listener only try to perform its operations if the flag is true. You could periodically try to regain a fix, say at 5-minute intervals, using a background Thread. If you believe this would be too much of a drain, have a counter running that increments each time you try to acquire a fix, and have the Thread stop trying after some set number of tries, then go to sleep for another specified interval before trying again.

 

That's what I did for my application, anyway, but I'm no expert. Take my advice with a grain of salt.

 

Hope that helps,

~Dom

----------------------------------------------------------------------------
chown -R us ./base
~J!NX
Contributor
Posts: 11
Registered: ‎02-26-2010
My Device: Curve 8310 & Curve 8530
My Carrier: 8310 on ATT 8530 on Sprint

Re: GPS Criteria and LocationListener Interface

i have thought of that solution and seen it in an article somewhere.....

 

I was just curious if the criteria approach would be any better.

 

Thanks for your input! Smiley Very Happy