订阅者未从eventBus获得发布的消息

编程入门 行业动态 更新时间:2024-10-28 00:23:55
本文介绍了订阅者未从eventBus获得发布的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想在我的应用程序中使用事件总线.为此,我将eventbus lib添加到了gradle中.然后,我创建了一个像这样的类:

I want to use eventbus into my app. for that I add eventbus lib to my gradle.then I have created a class like this:

public class UserEvent { private User eUser; // esup user model private String domain; private String securitySrv; private Cookie cookie; private int totalUsersSecurity; private ExecutorService executorService; // constructor and getter

然后在主要片段中添加以下行,最后我发布了消息:

then into main fragment I have added this lines and finally I have posted my message:

UserEvent userEvent = new UserEvent(eUser, domain, securitySrv, cookie, totalUsersSecurity, executorService); EventBus.getDefault().post(userEvent);

进入主片段,我有ViewPager,该传呼器已经加载了另一个名为 AllUsersFragment 的片段.

into main fragment I have ViewPager that this pager have loaded another fragment called AllUsersFragment.

首先在AllUsersFragment中注册了事件总线:

In AllUsersFragment first I have registered eventbus:

EventBus bus = EventBus.getDefault(); @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_layout, container, false); bus.register(this); return rootView; }

然后我写了这个方法:

@Subscribe public void onEvent(UserEvent event) { securitySrv = event.getSecuritySrv(); cookie = event.getCookie(); totalUsersSecurity = event.getTotalUsersSecurity(); executorService = event.getExecutorService(); }

进入我的简历方法中,我想通过其构造函数将UserEvent从eventbus传递到另一个类:

into my resume method I want to pass UserEvent from eventbus to another class by its constructor:

@Override public void onResume() { super.onResume(); paginator = new Paginator(getContext(),totalUsersSecurity,executorService); }

但是totalUsersSecurity和executorService为空吗?虽然这些变量是在主要片段中填充的.在android studio的调试模块中,从未调用过public void onEvent(UserEvent event). 谢谢你的帮助?

but totalUsersSecurity and executorService are null? while these variables was fill at main fragment.in debug mod at android studio this public void onEvent(UserEvent event) is not never called. thank you for helping?

我正在将Android Studio 3与gradle:3.0.0'一起使用

I am using android studio 3 with gradle:3.0.0'

推荐答案

最后,我解决了这个问题.根据 eventBus Wiki

Finally I fix this problem. according eventBus wiki

我只使用 Sticky Events .现在我收到了帖子

I just use Sticky Events .now I received my post

更多推荐

订阅者未从eventBus获得发布的消息

本文发布于:2023-11-24 11:19:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624996.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:消息   eventBus

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!