当前位置: 首页 > news >正文

在哪里建设网站商务网站内容建设包括

在哪里建设网站,商务网站内容建设包括,如何查询网站的注册信息查询,泉州市新濠网络科技有限公司EventBus 简介 EventBus#xff1a;github EventBus是Android和Java的发布/订阅事件总线。 简化组件之间的通信 解耦事件发送者和接收者 在 Activities, Fragments, background threads中表现良好 避免复杂且容易出错的依赖关系和生命周期问题 Publisher使用post发出…EventBus 简介 EventBusgithub EventBus是Android和Java的发布/订阅事件总线。 简化组件之间的通信 解耦事件发送者和接收者 在 Activities, Fragments, background threads中表现良好 避免复杂且容易出错的依赖关系和生命周期问题 Publisher使用post发出一个Event事件Subscriber在onEvent()函数中接收事件。 EventBus 是一款在 Android 开发中使用的发布/订阅事件总线框架基于观察者模式将事件的接收者和发送者分开简化了组件之间的通信使用简单、效率高、体积小下边是官方的 EventBus 原理图 导入 Android Projects implementation(org.greenrobot:eventbus:3.2.0)Java Projects: implementation(org.greenrobot:eventbus-java:3.2.0)dependencygroupIdorg.greenrobot/groupIdartifactIdeventbus-java/artifactIdversion3.2.0/version /dependency配置 配置混淆文件 -keepattributes *Annotation* -keepclassmembers class * {org.greenrobot.eventbus.Subscribe methods; } -keep enum org.greenrobot.eventbus.ThreadMode { *; }# If using AsyncExecutord, keep required constructor of default event used. # Adjust the class name if a custom failure event type is used. -keepclassmembers class org.greenrobot.eventbus.util.ThrowableFailureEvent {init(java.lang.Throwable); }# Accessed via reflection, avoid renaming or removal -keep class org.greenrobot.eventbus.android.AndroidComponentsImpl使用 简单流程 创建事件类 public static class MessageEvent { /* Additional fields if needed */ }在需要订阅事件的地方声明订阅方法并注册EventBus。 Subscribe(threadMode ThreadMode.MAIN) public void onMessageEvent(MessageEvent event) {// Do something }public class EventBusActivity extends AppCompatActivity {Overrideprotected void onCreate(Nullable Bundle savedInstanceState) {super.onCreate(savedInstanceState);}Overrideprotected void onStart() {super.onStart();//注册EventBusEventBus.getDefault().register(this);}//接收事件Subscribe(threadMode ThreadMode.POSTING, sticky true, priority 1)public void onReceiveMsg(MessageEvent message){Log.e(EventBus_Subscriber, onReceiveMsg_POSTING: message.toString());}//接收事件Subscribe(threadMode ThreadMode.MAIN, sticky true, priority 1)public void onReceiveMsg1(MessageEvent message){Log.e(EventBus_Subscriber, onReceiveMsg_MAIN: message.toString());}//接收事件Subscribe(threadMode ThreadMode.MAIN_ORDERED, sticky true, priority 1)public void onReceiveMsg2(MessageEvent message){Log.e(EventBus_Subscriber, onReceiveMsg_MAIN_ORDERED: message.toString());}Overrideprotected void onDestroy() {super.onDestroy();//取消事件EventBus.getDefault().unregister(this);} }提交订阅事件 OnClick(R2.id.send_event_common) public void clickCommon(){MessageEvent message new MessageEvent(1, 这是一条普通事件);EventBus.getDefault().post(message); }OnClick(R2.id.send_event_sticky) public void clickSticky(){MessageEvent message new MessageEvent(1, 这是一条黏性事件);EventBus.getDefault().postSticky(message); }Subcribe注解 Subscribe是EventBus自定义的注解共有三个参数可选threadMode、boolean sticky、int priority。 完整的写法如下 Subscribe(threadMode ThreadMode.MAIN,sticky true,priority 1) public void onReceiveMsg(MessageEvent message) {Log.e(TAG, onReceiveMsg: message.toString()); }priority priority是优先级是一个int类型默认值为0。值越大优先级越高越优先接收到事件。 值得注意的是只有在post事件和事件接收处理处于同一个线程环境的时候才有意义。 sticky sticky是一个boolean类型默认值为false默认不开启黏性sticky特性那么什么是sticky特性呢 上面的例子都是对订阅者 (接收事件) 先进行注册然后在进行post事件。 那么sticky的作用就是订阅者可以先不进行注册如果post事件已经发出再注册订阅者同样可以接收到事件并进行处理。 ThreadMode 模式 POSITING订阅者将在发布事件的同一线程中被直接调用。这是默认值。事件交付意味着最少的开销因为它完全避免了线程切换。因此对于已知可以在很短时间内完成而不需要主线程的简单任务推荐使用这种模式。使用此模式的事件处理程序必须快速返回以避免阻塞发布线程(可能是主线程)。 MAIN在Android上订阅者将在Android的主线程(UI线程)中被调用。如果发布线程是主线程将直接调用订阅者方法阻塞发布线程。否则事件将排队等待交付(非阻塞)。使用此模式的订阅者必须快速返回以避免阻塞主线程。如果不是在Android上行为与POSITING相同。 MAIN_ORDERED在Android上订阅者将在Android的主线程(UI线程)中被调用。与MAIN不同的是事件将始终排队等待交付。这确保了post调用是非阻塞的。 BACKGROUND在Android上订阅者将在后台线程中被调用。如果发布线程不是主线程订阅者方法将在发布线程中直接调用。如果发布线程是主线程EventBus使用一个后台线程它将按顺序传递所有事件。使用此模式的订阅者应尽量快速返回以避免阻塞后台线程。如果不是在Android上总是使用一个后台线程。 ASYNC订阅服务器将在单独的线程中调用。这始终独立于发布线程和主线程。使用此模式发布事件从不等待订阅者方法。如果订阅者方法的执行可能需要一些时间例如网络访问则应该使用此模式。避免同时触发大量长时间运行的异步订阅者方法以限制并发线程的数量。EventBus使用线程池来有效地重用已完成的异步订阅者通知中的线程。 /*** Each subscriber method has a thread mode, which determines in which thread the method is to be called by EventBus.* EventBus takes care of threading independently from the posting thread.* * see EventBus#register(Object)* author Markus*/ public enum ThreadMode {/*** Subscriber will be called directly in the same thread, which is posting the event. This is the default. Event delivery* implies the least overhead because it avoids thread switching completely. Thus this is the recommended mode for* simple tasks that are known to complete in a very short time without requiring the main thread. Event handlers* using this mode must return quickly to avoid blocking the posting thread, which may be the main thread.*/POSTING,/*** On Android, subscriber will be called in Androids main thread (UI thread). If the posting thread is* the main thread, subscriber methods will be called directly, blocking the posting thread. Otherwise the event* is queued for delivery (non-blocking). Subscribers using this mode must return quickly to avoid blocking the main thread.* If not on Android, behaves the same as {link #POSTING}.*/MAIN,/*** On Android, subscriber will be called in Androids main thread (UI thread). Different from {link #MAIN},* the event will always be queued for delivery. This ensures that the post call is non-blocking.*/MAIN_ORDERED,/*** On Android, subscriber will be called in a background thread. If posting thread is not the main thread, subscriber methods* will be called directly in the posting thread. If the posting thread is the main thread, EventBus uses a single* background thread, that will deliver all its events sequentially. Subscribers using this mode should try to* return quickly to avoid blocking the background thread. If not on Android, always uses a background thread.*/BACKGROUND,/*** Subscriber will be called in a separate thread. This is always independent from the posting thread and the* main thread. Posting events never wait for subscriber methods using this mode. Subscriber methods should* use this mode if their execution might take some time, e.g. for network access. Avoid triggering a large number* of long running asynchronous subscriber methods at the same time to limit the number of concurrent threads. EventBus* uses a thread pool to efficiently reuse threads from completed asynchronous subscriber notifications.*/ASYNC }相关文档 EventBus详解 (详解 原理)三幅图弄懂EventBus核心原理
http://www.w-s-a.com/news/851302/

相关文章:

  • 摄影素材库网站服装页面设计的网站
  • 如何用国外网站做头条做个游戏app的费用大概多少
  • 网站 形象入口页福州网站建设网络公司排名
  • 免费下载教学设计的网站送网站建设管理信息内容审核制度
  • 外贸专业网站的公司百度旗下13个app
  • 物理组简介 网站建设高师院校语言类课程体系改革与建设 教学成果奖申报网站
  • 爱网站无法登录怎么回事手表网
  • 网站建设公司现在还挣钱吗山西手动网站建设推荐平台
  • 重庆建设工程交易信息网站网站制作公司起名
  • 东莞寮步做网站的有吗企业宣传册制作
  • 做网站的软件是哪个上蔡做网站
  • 前后端分离实现网站开发紧急通知网页升级
  • 河北专业网站建设公司推荐佛山小程序开发平台
  • 网站开发强制开启浏览器极速模式建设网站有什么风险
  • 360全景网站建设常州专业网站建设公司咨询
  • 重庆大渡口网站建设网站增加一体化建设功能的好处
  • 网站开发完整视频网站上传 404
  • 自适应网站做推广北京建设工程招标网
  • 外贸网站设计注意事项网上商城官网入口
  • 正规的营销型网站建设公司微官网是网站吗
  • 南京行业门户网站无锡阿里巴巴做网站
  • 河北省和城乡住房建设厅网站wamp wordpress打不开
  • 在哪个平台做网站比较好自动app优化
  • 有没有能帮人快速网站备案的机构个人学做网站
  • 凌云县 城市建设 网站西安市建网站
  • 织梦xml网站地图公众号公众平台
  • 长春省妇幼网站做四维学校网站系统破解版
  • 安阳免费搭建自己的网站个人网站做商城会怎样
  • 网站建设专家公司排行网站举报有奖平台
  • 程序员不是做网站的公司装修效果全景图