我试图通过一个意图传递我的价值,如果它是从 Activity 到另一个 Activity,它工作得很好。但这次是从一个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);
}