由于某种原因,当我的应用程序放入后台时,onpause方法并不总是被调用。无论是那个还是MyLocationOverlay
都没有正确禁用。activity.on不总是被调用
我的应用程序使用谷歌地图和MyLocationOverlay
。当启动应用程序时,我在onResume
方法中调用MyLocationOverlay.enableMyLocation()
。在方法中,我呼叫MyLocationOverlay.disableMyLocation()
。但是,当我按Home键或后退键进入主屏幕时,GPS会按照带状态栏顶部所示的gps图标继续运行。
编辑:它不能在模拟器或手机上工作。
编辑2:当我使用高级任务杀手杀死它时,gps图标只会消失。
EDIT3:在onPause肯定是被称为我把日志语句,但在GPS图标保持。因此,它看起来像gps服务没有关闭,或者MyLocationOverlay
有一个disableMyLocation()
方法的错误。
这里是我的清单文件和节录从我的活动:
<?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>
活动
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();
}
任何帮助将不胜感激。
让我们知道这是否有效,或者如果您找到解决方案。我有同样的问题,我不使用Admob。 – ShadowGod 2010-10-01 07:49:13
我接受这个答案来代替更好的答案。如果有人想出更明确的答案,我会重新评估。 – Nemi 2010-10-04 16:38:16