Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old October 12th, 2010, 03:41 AM   #1 (permalink)
Junior Member
Thread Author (OP)
 
MrRalphMan's Avatar
 
Join Date: Aug 2010
Location: Billericay, UK
Posts: 17
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default Help with GPS app. No speed value after screen rotation

I'm playing with a GPS application and am having issues when the screen rotates.

The following is what I use to create the location updates and stop them when the screen rotates.

The app, when started shows the speed and location updates, once the screen rotates I no longer have the speed updates, although the location update procedure does kick in as the location changes and I update an elapsed time within it.

Here is the code, have I missed something obvious?

Code:
    @Override    
    public void onResume() { 
        super.onResume();
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        if(gps<2){
            try {
                // get location manager to check gps availability
                boolean isGPS = locationManager.isProviderEnabled (LocationManager.GPS_PROVIDER); 
    
                if(!isGPS){
                    gps++;
                    if(gps<2) checkGps();
                    else finish();
                }
                else{
                    gps=2;                
                    //gps is available, do actions here    
                    
                }                
            
             } catch (Exception e1) {
                 gps++;
                 if(gps<2) checkGps();
                 else finish();
            }
        }
        
        if (listenerFine == null){
            
            listenerFine = null;
        }
            
        
        listenerFine = new LocationListener() {
            
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
                // TODO Auto-generated method stub
                
            }
            
            @Override
            public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub
                
            }
            
            @Override
            public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub
                
            }
            
            @Override
            public void onLocationChanged(Location location) {
                // TODO Auto-generated method stub
                speed = location.getSpeed() ;
                
                <Other stuff being updated etc in here>
                
            }
        };
        

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L,1.0f, listenerFine);

        
        
    }
    
    public void onPause() {
        super.onPause();
        locationManager.removeUpdates(listenerFine);
        
        
    }

Advertisements
MrRalphMan is offline  
Reply With Quote
sponsored links
Old October 12th, 2010, 12:31 PM   #2 (permalink)
cp1
Member
 
Join Date: Apr 2010
Posts: 375
 
Device(s):
Carrier: Not Provided

Thanks: 13
Thanked 35 Times in 30 Posts
Default

When the screen is rotated the entire app is killed and restarted from OnCreate, so the problem might not be in your pause/resume procedures.
cp1 is offline  
Reply With Quote
Old October 13th, 2010, 04:56 AM   #3 (permalink)
Junior Member
Thread Author (OP)
 
MrRalphMan's Avatar
 
Join Date: Aug 2010
Location: Billericay, UK
Posts: 17
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by cp1 View Post
When the screen is rotated the entire app is killed and restarted from OnCreate, so the problem might not be in your pause/resume procedures.
Yeah, I know the activity is destroyed/recreated on rotation, thus the onResume/onPause portions of the app.
onResume is also called when the activity is created, as the speed works the first time the activity is opened, but not after rotation.

What is weird is that the onLocationChange method is still being called every second as the location and time elapsed, which I calculate in the method, are being updated.
The Speed isn't.

I am missing something obvious and if I could get the DDMS working with the emulator to play GPX files, I could have a nose around while debugging, but it will not recognise any files (GPX and KML) that I have.

Cheers,

Paul.
MrRalphMan is offline  
Reply With Quote
Old October 13th, 2010, 08:33 PM   #4 (permalink)
cp1
Member
 
Join Date: Apr 2010
Posts: 375
 
Device(s):
Carrier: Not Provided

Thanks: 13
Thanked 35 Times in 30 Posts
Default

Can you just step through it in the debugger? Is gps being set correctly before the on resume? I'm not sure why all this is in onresume, it seems that oncreate is a more appropriate place to set up all your listeners and stuff. But I've never made a gps app, so maybe that's the standard.
cp1 is offline  
Reply With Quote
Old October 14th, 2010, 01:13 AM   #5 (permalink)
Junior Member
Thread Author (OP)
 
MrRalphMan's Avatar
 
Join Date: Aug 2010
Location: Billericay, UK
Posts: 17
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hiya,

Thanks for the reply, I would go through it with the debugger, but cannot get a test god feed running, either through a nmea file is the test provider on the device, nor through playing a gpx/kml file through ddms.

That's my next task so I cab see what's going on.

Cheers,

Paul
MrRalphMan is offline  
Reply With Quote
Old October 17th, 2010, 03:40 PM   #6 (permalink)
cp1
Member
 
Join Date: Apr 2010
Posts: 375
 
Device(s):
Carrier: Not Provided

Thanks: 13
Thanked 35 Times in 30 Posts
Default

If all you want to do is check the operation of the app, why do you have to feed it a gps coordinate file? Can't you just use wherever your emulator thinks it is, or even use your own phone to debug?
cp1 is offline  
Reply With Quote
Old October 18th, 2010, 12:27 AM   #7 (permalink)
Junior Member
Thread Author (OP)
 
MrRalphMan's Avatar
 
Join Date: Aug 2010
Location: Billericay, UK
Posts: 17
 
Device(s): HTC Desire
Carrier: Not Provided

Thanks: 2
Thanked 0 Times in 0 Posts
Default

Hi,

I can test the basic operations of the app, but when running the app on the phone, when it rotates the speed value stops being picked up from the location object.
I would like to be able to test it against a known gps track on the emulator for ease of debugging and be able test further functions.
There are a couple of order small niggles that is like to iron out.

Cheers for the advice, but I'm going to get the gps tracks running even if it kills me.
Paul
MrRalphMan is offline  
Reply With Quote
Reply
Tags
gps, onlocationchange, rotation


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:00 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.