2010-12-28 1 views
0

GPSを使用して開始する単純なlocationListenerがあります。 Inside OnLocationChanged私はジオコードルックアップを行い、トーストメッセージを表示します。問題は、GPSがまだ更新を受けていて、Toastoを処理していても、アクティビティが最前面になくなることです。私はonStart、onPause、onDestroyとonStopでRemoveUpdatesを持っています。ジオコードトーストを使用したLocationListenerは、アクティビティが「OnCreate」を残すと停止しません。

なぜ私はこのサービスを停止できないのでしょうか?ここで

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    mapView = (MapView) findViewById(R.id.mapView); 
    mc = mapView.getController(); 

    locationListener = new GPSLocationListener(); 
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);   
    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,locationListener);  

... 
...  

public void onStart(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

public void onPause(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

public void onDestroy(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

public void onStop(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

class GPSLocationListener implements LocationListener {  
    @Override 
    public void onLocationChanged(Location location) { 
     if (location != null) { 

      current_heading=location.getBearing(); 
      String current_bearing = headingToString2(location.getBearing()); 

      point = new GeoPoint(
       (int) (location.getLatitude() * 1E6), 
       (int) (location.getLongitude() * 1E6)); 

      // add marker 
      MapOverlay mapOverlay = new MapOverlay(); 
      mapOverlay.setPointToDraw(point); 
      List<Overlay> listOfOverlays = mapView.getOverlays(); 
      listOfOverlays.clear(); 
      listOfOverlays.add(mapOverlay); 

      mapView.setStreetView(showStreet); 
      // enable to show Satellite view 
      mapView.setSatellite(showSatellite);   
      // enable to show Traffic on map 
      mapView.setTraffic(showTraffic);   
      mapView.setBuiltInZoomControls(true); 

      mc.animateTo(point); 
      mc.setZoom(16); 

      address = ConvertPointToLocation(point); 
      Toast.makeText(getBaseContext(), address, Toast.LENGTH_LONG).show(); 
      Toast.makeText(getBaseContext(), address, Toast.LENGTH_LONG).cancel(); 
      }  
    } 

ホーム

12-28 16:41:51.402: ERROR/LocationMasfClient(577): reverseGeocode(): GLS failed with status 20 
12-28 16:41:51.423: INFO/NotificationService(577): enqueueToast pkg=com.kuli.example.android511 [email protected] duration=1 
12-28 16:41:53.272: DEBUG/LocationMasfClient(577): getAddressFromProtoBuf(): Ignore feature 0,Lyndon Station 
12-28 16:41:53.282: INFO/NotificationService(577): enqueueToast pkg=com.kuli.example.android511 [email protected] duration=1 
12-28 16:41:55.533: DEBUG/dalvikvm(633): GC freed 715 objects/92504 bytes in 324ms 
12-28 16:41:57.883: INFO/ActivityManager(577): Starting activity: Intent { action=android.intent.action.MAIN categories={android.intent.category.HOME} flags=0x10200000 comp={com.android.launcher/com.android.launcher.Launcher} } 
12-28 16:41:57.932: DEBUG/LocationManager(1191): removeUpdates: listener = [email protected]f40 
12-28 16:41:57.952: DEBUG/AndroidRuntime(1191): Shutting down VM 
12-28 16:41:57.952: WARN/dalvikvm(1191): threadid=3: thread exiting with uncaught exception (group=0x4000fe70) 
12-28 16:41:57.966: ERROR/AndroidRuntime(1191): Uncaught handler: thread main exiting due to uncaught exception 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191): android.app.SuperNotCalledException: Activity {com.kuli.example.android511/com.kuli.example.android511.android511} did not call through to super.onPause() 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2830) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.app.ActivityThread.performPauseActivity(ActivityThread.java:2797) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.app.ActivityThread.handlePauseActivity(ActivityThread.java:2780) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.app.ActivityThread.access$2000(ActivityThread.java:112) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1699) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.os.Handler.dispatchMessage(Handler.java:99) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.os.Looper.loop(Looper.java:123) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at android.app.ActivityThread.main(ActivityThread.java:3948) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at java.lang.reflect.Method.invokeNative(Native Method) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at java.lang.reflect.Method.invoke(Method.java:521) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) 
12-28 16:41:57.972: ERROR/AndroidRuntime(1191):  at dalvik.system.NativeStart.main(Native Method) 
12-28 16:41:57.992: INFO/Process(577): Sending signal. PID: 1191 SIG: 3 
12-28 16:41:57.992: INFO/dalvikvm(1191): threadid=7: reacting to signal 3 
12-28 16:41:58.133: INFO/dalvikvm(1191): Wrote stack trace to '/data/anr/traces.txt' 
12-28 16:41:58.442: WARN/ActivityManager(577): Activity pause timeout for HistoryRecord{437b5170 {com.kuli.example.android511/com.kuli.example.android511.android511}} 
12-28 16:43:08.393: DEBUG/dalvikvm(631): GC freed 9811 objects/553776 bytes in 104ms 
+0

hmmmmmをオーバーライドしている方法に@Override注釈を追加することに慣れる必要がありますする必要があります。同じように? – Kuli

答えて

2

を行くしようとするあなたはどのメソッドをオーバーライドしていないときLogCatです。

public void onStart(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

public void onPause(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

public void onDestroy(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

public void onStop(Bundle savedInstanceState) { 
    locationManager.removeUpdates(locationListener); 
    locationManager=null; 
} 

これらのメソッドのシグネチャではありません。それは

@Override 
protected void onStart(){ 

} 

など

あなたは、私がlocationListener = NULLを設定する必要がある場合、私は疑問に思う、あなたが

+0

脳のおなら...ありがとう!!! – Kuli

+0

ただし、アプリケーションを終了するとエラーが発生します... – Kuli

+0

http://developer.android.com/reference/android/location/LocationManager.html#removeUpdates%28android.appにはおそらくIllegalArgumentExceptionが発生しています。 PendingIntent%29です。あなたはもう助けになるためにlogcatからエラーを投稿しなければなりません。 – Falmarri

関連する問題