I apologize profusely right at the start, because I know that answering this question is going to be like nailing jello to a wall. I'll give as many details as I can, but there aren't many to give.
I'm developing a Blackberry app that uses GPS to get a user's location every xx minutes (could be 15, 30, or 60 depending on the preferences the user sets); it sends the location data to a web service.
It runs fine and reports the user's location fine, but only for about 16-18 hours, and then the app stops reporting and the user-interface no longer works. Doesn't throw any errors, it just won't respond to user selections anymore until the app is re-booted.
It's strange to me that the app crash is fairly predictable - it never crashes after, say, 8 hours, or 10 hours, it's always in that 16-18 hour window, which suggests to me that the crash is related to the GPS/WebService reporting.
Basically, if I look at it from the GPS/WebService standpoint, it looks as though the app can manage to report to the WebService 36 times (every half-hour for 18 hours), and then it dies.
I'll post a bit of the code here in the hopes that it will trigger an idea for someone.
private void updateGPSLocation(){
gps_interval_timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
try{
getGPSLocation();
if(longitude != 0.0 && latitude != 0.0)
{
updateSubscriberLocation();
}
}catch(Exception ex){
}
}
}, 0, gps_interval);
}
And here's the code for the getGPSLocation() call referenced in the previous code:
public void getGPSLocation(){
try{
//GPS thread
BlackBerryLocationProvider provider = (BlackBerryLocationProvider)LocationProvider.getInstance(new BlackBerryCriteria(GPSInfo.GPS_MODE_ASSIST));
//geolocation thread
BlackBerryLocationProvider provider1 = (BlackBerryLocationProvider)LocationProvider.getInstance(new BlackBerryCriteria(LocationInfo.GEOLOCATION_MODE_CELL));
if (provider != null){
provider.setLocationListener(new LocationListenerImpl(), _interval, 1, 1);
}
if(provider1 != null){
provider1.setLocationListener(new LocationListenerImpl(), _interval, 1, 1);
}
}
catch(Exception le){
}
}
Again, I'm sorry, I know this is kind of an open-ended question. Are there any known issues with the Blackberry GPS? Because I'm scheduling the interval-based reporting using a timer task, is it possible that I'm just sucking up all the available memory by putting scheduled timer tasks in the queue? Do I need to explicitly dispose of the timer task using the cancel() method? Something like:
gps_interval_timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
try{
getGPSLocation();
if(longitude != 0.0 && latitude != 0.0)
{
updateSubscriberLocation();
}
}catch(Exception ex){
}
finally
{
this.cancel();
}
}
}, 0, gps_interval);
Any help is most appreciated. Thank you!
UPDATED WITH LocationListener code
private class LocationListenerImpl implements LocationListener {
public void locationUpdated(LocationProvider provider, Location location) {
if(location.isValid()) {
longitude = location.getQualifiedCoordinates().getLongitude();
latitude = location.getQualifiedCoordinates().getLatitude();
}
}
public void providerStateChanged(LocationProvider provider, int newState) {
}
}
The _interval variable used in getGPSLocation() is set at -1.