2012-11-15 64 views
0

我寫了一個服務來管理位置問題。它完美地運行在2.3.3(Galaxy S2)上,但是當我在ICS(Galaxy s3)上運行應用程序時,onDestroy方法被調用。他們之間可能的差異是什麼?爲什麼服務會在ICS上銷燬而不是以前的版本?

編輯1: 問題在下面的行。爲什麼或如何強制摧毀服務?

_locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME, MIN_DISTANCE, this);

EDIT 2(問題)

  1. 如果GPS被禁用它不會打開GPS和進入的onDestroy
  2. 如果網絡提供者所選擇的提供者然後去onDestroy再次。

點我不能得到它如何正確地運行在所有這些2.3.3?

private void turnGPSOn(){ 
     String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); 

     if(!provider.contains("gps")){ //if gps is disabled 
      final Intent poke = new Intent(); 
      poke.setClassName("com.android.settings", "com.android.settings.widget.SettingsAppWidgetProvider"); 
      poke.addCategory(Intent.CATEGORY_ALTERNATIVE); 
      poke.setData(Uri.parse("3")); 
      sendBroadcast(poke); 
     } 
    } 

getBestProvider()

private String getBestProvider(){ 
    //gps açıksa fine'a göre ara, değilse dandik providerı dön. 
    return isGpsEnabled()==true ? _locationManager.getBestProvider(getFineCriteria(), false) : _locationManager.getBestProvider(getCoarseCriteria(), false); 
} 
+2

也許有些代碼會有幫助嗎?那麼LogCat呢?有消息嗎? – RvdK

+0

您應該在logcat中看到一些消息來指出問題。 –

回答

0

它們之間的最有可能的區別是內存管理,ICS佔用更多的內存空間,Android的進程管理器破壞某些服務,並在你的情況稱爲服務是一個他們。

相關問題