アクティビティから別のアクティビティへの場合は正常に機能するインテントを介して値を渡そうとしました。しかし今回はActivityからServiceへ。これは正しいアプローチだと思いましたか?しかし、私はエラーサービスクラスを取得しています
マイ アクティビティ
@Override
protected void onPause() {
// TODO Auto-generated method stub
myLocation.disableCompass();
super.onPause();
locationManager.removeUpdates(this);
Intent intent = new Intent(this, LocationLoggerService.class);
intent.putExtra("midllat", midllat);
intent.putExtra("midlongi", midlongi);
startActivity(intent);
}
私のサービスクラス
@Override
public void onCreate() {
// Find my current location
locationManager = (LocationManager) this
.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
2000, 0, this);
Criteria crit = new Criteria();
towers = locationManager.getBestProvider(crit, false);
Location location = locationManager.getLastKnownLocation(towers);
Toast.makeText(this, "The app is know running in the background",
Toast.LENGTH_LONG).show();
gm = new GoogleMaps();
getIntent() でエラーが発生しました。メソッドが見つかりません。サービス クラスにあるためですか? 何をすべきか?
Intent intent = getIntent();
String test1 = intent.getStringExtra("midllat");
String test2 = intent.getStringExtra("midlongi");
midllat = Double.parseDouble(test1);
midlongi = Double.parseDouble(test2);
}