【发布时间】:2017-12-07 14:07:47
【问题描述】:
我有一个在单独的 java 上运行的定位服务:
public class GPSService extends Service implements LocationListener,
GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener {
Intent intent;
LocationRequest mLocationRequest;
GoogleApiClient mGoogleApiClient;
Location mLastLocation;
String lat, lon;
public static String str_receiver = "servicetutorial.service.receiver";
我想使用另一个类的意图从中检索 mLastLocation,以将该位置作为 func MyFunc 的输入传递
如果我使用
startService(new Intent(this, GPSService.class));
GPSService obj = new GPSService ();
MyFunc(obj.mLastLocation);
可以编译,但是传递的Location对象为空
我需要使用 put 和 get Extras 吗?在 Location 变量的情况下如何使用它?我也需要使用 put 吗?
注意:服务正常运行并按设计进行更新。 谢谢。
【问题讨论】:
-
为什么不能使用广播接收器?
标签: android android-intent service extra