2011-08-16 11 views
3

私のアプリケーションでは、onStart()メソッドで "requestLocationUpdates"を呼び出して、アップデートを正しく受信します。GPSシステムが "removeUpdates"を呼び出した後に再起動しない

「removeUpdate(locationlistener)」を呼び出してGPSをオフにすると、予想通りに更新が受信されなくなります。

問題は、「requestLocationUpdates」メソッドを再度呼び出すことによってGPSシステムを再起動したいときに、動作していないことです。 "onLocationChanged"または "onStatusChanged"メソッドを入力することはありません。

my gpsLocationListener code;

public final LocationListener gpsLocationListener = new LocationListener() { 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     switch (status) { 
     case LocationProvider.AVAILABLE: 
      Logging.TraceMessage("GPS available again", Logging.INFORMATION, Logging.MAINACTIVITY); 
      break; 
     case LocationProvider.OUT_OF_SERVICE: 
      Logging.TraceMessage("GPS out of service", Logging.INFORMATION, Logging.MAINACTIVITY); 
      deviceSettings.gpsStatus = "2"; 
      break; 
     case LocationProvider.TEMPORARILY_UNAVAILABLE: 
      Logging.TraceMessage("GPS temporarily unavailable", Logging.INFORMATION, Logging.MAINACTIVITY); 
      break; 
     } 
    } 

    public void onProviderEnabled(String provider) { 
     Logging.TraceMessage("GPS Provider Enabled", Logging.INFORMATION, Logging.MAINACTIVITY); 
    } 

    public void onProviderDisabled(String provider) { 
     Logging.TraceMessage("GPS Provider Disabled", Logging.INFORMATION, Logging.MAINACTIVITY); 
     deviceSettings.gpsStatus = "2"; 
    } 

    public void onLocationChanged(Location location) { 
     if(location == null) return; 

     tempLoc.setItem(location.getLongitude(), location.getLatitude(), deviceSettings.getCurrentTime(), deviceSettings.satelliteCount, location.getSpeed()); 
      if (!SafeLocation.IsSafe(tempLoc)){ 
      return; 
     } 

     deviceSettings.currX = tempLoc._x; 
     deviceSettings.currY = tempLoc._y; 
     deviceSettings.currSpeed = tempLoc._speed; 
     deviceSettings.currValid = true; 

    } 
}; 

my removeupdates code;

if(! deviceSettings.isprogramModeActive){ 

         if(gpsLocationListener != null){ 
          try { 
           locationManager.removeUpdates(gpsLocationListener); 
          } catch (Exception e) { 
          }       
         } 
         mylocatewait(30000);//30 saniye bekle 
         continue; 
        } 

私の要求を再びコード:

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, ServerSettings.getGpsPer()*1000, 0, gpsLocationListener); 
+1

私はあなたがトルコ人だと知っていますが、あなたの質問の文法は、あなたが望むプログラムの流れを理解するのを困難にします。 – Ian

+0

申し訳ありません、私はそれを編集しました。あなたがすでにそれを理解していないか教えてください。 –

+1

デバイスでエミュレートしたり実行したりしていますか? DMMS経由で場所を送信していますか? – Ian

答えて

1

が、私は問題を解決!

スレッドからハンドラを呼び出す。

locateHandler.sendEmptyMessage(1); 

スレッドではなくハンドラから次のコードを呼び出します。

Handler locateHandler = new Handler() { 
     @Override 
     public void handleMessage(Message msg) { 
      super.handleMessage(msg); 
      if(msg.what == 0) 
       locationManager.removeUpdates(gpsLocationListener); 
      else if(msg.what == 1) 
       locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, ServerSettings.getGpsPer()*1000, 0, gpsLocationListener); 
     } 
    }; 
+0

ハンドブック。ポストは、おそらく、おしゃれなクリーナーですが、 – njzk2

+0

は回答としてあなたの投稿を受け入れます。 – Ian

+0

私はそれを受け入れます、7時間後(stackoverflow品質standarts) –

関連する問題