Android 中 Activity 的服务回调

2024-05-22

我有我的 GPSTracker 的摘要。它返回用户的位置。其作品。

public class GPSTracker extends Service implements LocationListener {


public GPSTracker(Context context) {
    this.mContext = context;
    getLocation();

}

public Location getLocation() {
    //GET LOCATION CODE
    return location;
}

因此,我使用以下代码在 MainActivity 中调用此服务:

gps = new GPSTracker(this, marker, googleMap, playbackService);

它正在获取用户的实际位置。我想在我的活动中获取此位置。该服务需要将位置发送到我的活动。谁能帮我?


根据您的要求,活动和服务可以通过 3 种方式进行通信,使用:

1) 广播接收器 https://androidexperinz.wordpress.com/2012/02/14/communication-between-service-and-activity-part-1/

2) Aidl – Android 界面定义语言 https://androidexperinz.wordpress.com/2012/02/21/communication-between-service-and-activity-part-2/

3) 信使 https://androidexperinz.wordpress.com/2012/12/14/communication-between-service-and-activity-part-3/

只需单击每种方法即可查看哪种方法满足您的需求。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android 中 Activity 的服务回调 的相关文章

随机推荐