我想从 Activity 类获取经纬度值到 JobService。我怎样才能做到这一点?我曾尝试将 Intent 与 putExtras 等一起使用(请查看下面的代码),但无法正确使用。
MainActivity.class
protected void createLocationRequest(Bundle bundle) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, new LocationCallback() {
@Override
public void onLocationResult(final LocationResult locationResult) {
Log.i("onLocationResult", locationResult + "");
latitude = locationResult.getLastLocation().getLatitude() + "";
longitude = locationResult.getLastLocation().getLongitude() + "";
Log.e("onLocationResult lat", latitude);
Log.e("onLocationResult Lon", longitude);
//I need to send latitude and longitude value to jobService?
//how to do that?
//tried using intent but didn't seem to work
//Intent mIntent = new Intent();
//mIntent.putExtra("lat", latitude);
//mIntent.putExtra("lon", longitude);
}
}, null);
}
MyJobService 类
public class MyJobService extends JobService {
@Override
public boolean onStartJob(JobParameters jobParameters) {
//I need to get latitude and longitude value here from mainActivity
return true;
}
}