我需要将3个浮点数传递给一个服务,最后服务需要发回'true'或'false'布尔值。将值传递给Service,intentService或bindService?
我读了关于这两个,但不知道我需要用什么, 一个例子将不胜感激。
我需要将3个浮点数传递给一个服务,最后服务需要发回'true'或'false'布尔值。将值传递给Service,intentService或bindService?
我读了关于这两个,但不知道我需要用什么, 一个例子将不胜感激。
关于第一个问题:传递对位意向服务
Using putExtra to pass values to intent service
,以及有关从意向服务发送通知发回活动:
Using ResultReceiver in Android
或尝试使用回调接口在服务和实施它的活动
// on intent service
private onGetNotification notify=(onGetNotification)contextOfActivity;
public interface onGetNotification {
public setOnGetNotification(Boolean result);
}
// use when finish
public void endOfService(){
notify.setOnGetNotification(true);
}
希望帮助:)
感谢拉米,它看起来不错,我会尝试,如果我的服务是激活一个类,并且这个类获取3个参数并计算它们,并在最后发回一个结果。我仍然需要使用你的答案吗?有些不同? –
@ Hadar.S你可以使用ResultReceiver更好 –
谢谢Ramy,看起来像一个很棒的解决方案。会尝试。 –
你是什么意思的“在服务的最后”? –
我对这项服务的评价。我只需要从服务返回一个布尔值到主要活动,所以指标虚拟led将会改变。 –