Reputation: 3061
For some reason the onpause method is not always getting called when my app is put into the background. Either that or the MyLocationOverlay
is not properly disabling.
My app uses google maps and the MyLocationOverlay
. When starting the app, I call MyLocationOverlay.enableMyLocation()
in the onResume
method. In the onPause
method I call MyLocationOverlay.disableMyLocation()
. However, when I hit the home key or the back key to go to the home screen, the GPS stays running as indicated by the top of the status bar with the gps icon.
EDIT: It does not work on either the emulator or the phone.
EDIT2: the gps icon only goes away when I use Advanced Task Killer to kill it.
EDIT3: onPause is definitely being called as I put a Log statement in it, but the gps icon remains. Therefore it looks like either the gps service isn't shutting down, or the MyLocationOverlay
has a bug with the disableMyLocation()
method.
Here is my manifest file and excerpts from my Activity:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res/com.tfb"
package="com.tfb"
android:versionName="1.2.2" android:versionCode="11">
<application android:icon="@drawable/globe_search"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<activity android:name=".activity.GarageSaleMap"
android:label="@string/app_name"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable"/>
</activity>
<uses-library android:name="com.google.android.maps" />
<meta-data android:value="xxxxxxxxxxx" android:name="ADMOB_PUBLISHER_ID"/>
<meta-data android:value="true" android:name="ADMOB_ALLOW_LOCATION_FOR_ADS"/>
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="8"/>
</manifest>
Activity
private void doMain() {
mapView = (MapView) findViewById(R.id.mapview);
MapView localMapView = mapView;
localMapView.setBuiltInZoomControls(true);
final MapController controller = localMapView.getController();
localMapView.getZoomButtonsController().setAutoDismissed(false);
lastSearchButton = (ImageButton) findViewById(R.id.lastSearchButton);
lastSearchButton.setOnClickListener(new LastSearchButtonListener(this));
GeoPoint point = new GeoPoint((int)(40.8138 * 1e6), (int)(-96.6831 * 1e6));//Lincoln, NE
controller.animateTo(point);
controller.setZoom(13);
pushPinItemizedOverlay = getPushPinOverlay();
localMapView.getOverlays().add(pushPinItemizedOverlay);
new PopulateMapTask(this).execute();
locationOverlay = new FixedMyLocationOverlay(this, localMapView);
localMapView.getOverlays().add(locationOverlay);
}
@Override
protected void onPause() {
locationOverlay.disableMyLocation();
super.onPause();
}
@Override
protected void onResume() {
locationOverlay.enableMyLocation();
super.onResume();
}
Any help would be greatly appreciated.
Upvotes: 1
Views: 1513
Reputation: 3061
I am not positive, but I think this may be from the admob ad plugin I am using. If I start my app and then immediately hit home, the gps icon does not go away. However, if I leave the app running for a bit and come back later and hit home, the icon does go away. Maybe the admob plugin (which I am allowing to get location data) is blocking gps shutdown until it gets a gps timeout or something (I have only tested inside where no satellites are available).
Not sure when I will have time, but I will have to test by removing the admob plugin to see, but maybe this will help someone else in the meantime.
EDIT1: More info, I have found that if the gps icon is blinking it is still trying to lock onto a location. This is when my gps indicator will not go away when I back out of the app. However, if the icon is steady (indicating a lock on a location), then it will go away when exiting the app. Appears to be a timeout issue. (I don't have a unit to test the admob hypothesis on right now).
Upvotes: 1
Reputation: 1007624
However, when I hit the home key or the back key to go to the home screen, the GPS stays running as indicated by the top of the status bar with the gps icon.
If this is on the emulator, that is an issue with the emulator. Once the GPS status icon appears, it never seems to go away.
Upvotes: 0