- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试从我的 WS 获取位置并更新我的 GoogleMap fragment 中的标记,所以我正在做的是:
我的 HomeActivity 包含 2 个 fragment (2 个 GoogleMaps,其中一个有 TileOverlay)。
在我的 GoogleMap fragment 中,我试图从 OnCameraChangeListener 获取我的标记位置,以便在用户移动时添加标记。
我正在使用 EventBus 和 Okhttp 进行异步请求!
我的 GoogleMapFragment:
public class GoogleMapFragment extends FragmentBase {
@Override
public void onResume() {
mapView.onResume();
BusHelper.register(this); // Register the EventBus with my helper
super.onResume();
}
@Override
public void onPause() {
BusHelper.unregister(this); // Unregister the EventBus with my helper
super.onPause();
}
public GoogleMap.OnCameraChangeListener getCameraChangeListener() {
return new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
//those are corners of visible region
VisibleRegion visibleRegion = mMap.getProjection().getVisibleRegion();
LatLng farLeft = visibleRegion.farLeft;
LatLng farRight = visibleRegion.farRight;
LatLng nearLeft = visibleRegion.nearLeft;
LatLng nearRight = visibleRegion.nearRight;
double minY = nearLeft.latitude;
double minX = nearLeft.longitude;
double maxY = farRight.latitude;
double maxX = farRight.longitude;
//Send the WS Request to a manager who uses okhttp
ApiManager.getPositions(minX, minY, maxX, maxY);
}
};
}
//Receive the eventBus event
public void onEvent(GetPositionsEvent event) {
if (event.positions != null)
setMarkersByVisibleRegion(event.positions);
}
之后它将在 APIManager 中执行 WS 请求。
public class IMSApiManager {
private final static Gson gson = new Gson();
private static Positions mPositions;
/**
* @return Positions
*/
public static void getPositions(double minX, double minY, double maxX, double maxY) {
String TAG = "getPositions";
String wSRequest = AppConstants.REQUEST_POSITIONS
.replace("{vUser}", "CARREPH1")
.replace("{vMinX}", new BigDecimal(minX).toPlainString())
.replace("{vMinY}", new BigDecimal(minY).toPlainString())
.replace("{vMaxX}", new BigDecimal(maxX).toPlainString())
.replace("{vMaxY}", new BigDecimal(maxY).toPlainString());
try {
RestAsyncHttpClient.doGetRequest(wSRequest, new GetPositionsCallback() {
@Override
public void onFailure(Request request, IOException e) {
super.onFailure(request, e);
}
@Override
public void onResponse(Response response) throws IOException {
super.onResponse(response);
mPositions = gson.fromJson(response.body().charStream(), Positions.class);
BusHelper.post(new GetPositionsEvent(mPositions)); //Post the eventBus
}
});
} catch (IOException exp) {
LogHelper.error(TAG, "Error getting positions", exp);
}
}
我熟悉 Not on the mainThread 错误,但理论上这是可能的,如果不是,我如何在不创建 fragment 的新实例的情况下添加标记。
最佳答案
接受的答案仅适用于低于第三个版本,对于其他版本,您应该使用 threadMode = ThreadMode.MAIN ( documentation )
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(MessageEvent event) {
textField.setText(event.message);
}
关于android - EventBus 不在主线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29040333/
我经常使用 greenrobot 的 EventBus https://github.com/greenrobot/EventBus 但我刚刚意识到 Guava 有自己的 EventBus com.g
对于 EventBus,我将代码合并到我的 java Spring 应用程序中并完全控制它,但结果没有改变。 当我在 spring sts (javaw) 中运行 EventBus 时,没有问题,但是
我想做的是将一个事件从另一个 AWS 账户发送到我的包含事件总线的账户。 为此,我正在尝试将角色/策略附加到 EventBus,但我做不到。我尝试使用 grantPutEvents 但也没有运气。这个
我想做的是将一个事件从另一个 AWS 账户发送到我的包含事件总线的账户。 为此,我正在尝试将角色/策略附加到 EventBus,但我做不到。我尝试使用 grantPutEvents 但也没有运气。这个
我是这个 eventbus 库的粉丝,并且在其他项目中很好地使用了它,没有遇到任何问题。但是现在,我在 Activity 中注册事件总线时遇到了一些奇怪的问题,并且在这里卡住了这部分... java.
我目前正在使用 Fragments 在 Activities 下创建的 FragmentPagerAdapter。我使用 GreenRobot 的 EventBus 3.0 返回我从服务类创建的一些
前沿 vue组件非常常见的有父子组件通信,兄弟组件通信。而父子组件通信就很简单,父组件会通过 props 向下传数据给子组件,当子组件有事情要告诉父组件时会通过 $emit 事件告诉父组件。如果1个页
早晨, 我正在使用 SimpleEvent总线将数据从我的集中式数据恢复器发送到小部件。这真的很好用,我从服务器获得一组新数据,RPC 调用的成功方法将它放在 Eventbus 上,每个小部件查看数据
我在Android应用程序中使用EventBus。在我的Eventbus.getDefault().register(this)中编写一个Application.onCreate()是一个好主意吗?我
我正在尝试使用 Vertx 上传文件,该请求是包含 PDF 的 POST 请求,我的处理程序如下所示(我从 github 中的示例中获取了代码): ... Set fileUploadSet = ro
所以我在 Vue.js 中使用 EventBus 将数据从一种方法发送到另一种方法。我有两种方法,比方说 one() 和 two()。我正在使用 EventBus,如下所示: one() { Ev
我有一个使用这个库的情况 greenrobot/EventBus保存数据并将它们传递给不同的 Activity 。在这种情况下,我使用 EventBus 来传递“订单”和 “cartItems” OB
我使用 greenrobot 作为 eventbus 来发布一些粘性事件。一切正常,当我打开应用程序时,ex。显示的内容表明粘帖工作正常。 但是当我关闭应用程序并打开它第二次、第三次……时,没有前任。
我在使用 EventBus 3.0.0 时遇到问题,我在其中发布了一个这样的事件: Call> call = httpService.getSessionSpecs(); call.enqueue(n
我在 android 中学习事件总线(http://greenrobot.org),我有以下代码 public class MainActivity extends AppCompatActivity
我正在尝试弄清楚如何在我的 AppWidgetProvider 中使用 Greenbot Eventbus 库。我尝试了以下方法,但没有用: public class SimpleWidgetProv
在我的安卓应用中我使用 org.greenrobot.eventbus.EventBus; 1.我创建事件: public class NotLoginEvent { } 在我的 fragment 中
我正在尝试从我的 WS 获取位置并更新我的 GoogleMap fragment 中的标记,所以我正在做的是: 我的 HomeActivity 包含 2 个 fragment (2 个 GoogleM
我正在尝试在我所有对话的基类中实现一些通用逻辑和对某些事件的 react 。 并在 EventBus 中注册和注销,并在基类中捕获一些事件。 因此,当我尝试实例化派生类的实例时 - EventBus
我在库中有一个带注释的 Activity,它是同一库中 EventBus 事件的订阅者。它看起来像这样,大大简化了: @EActivity(resName = "activity_foo") publ
我是一名优秀的程序员,十分优秀!