由於某種原因,當我的應用程序放入後臺時,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