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.