just looked under the author released the new version Androideventbus v1.0.4 version, found that a lot of good things, the biggest two features is the addition of sticky sticky events and no manual logoff events
Androideventbus's GitHub address is: GitHub
The following is the author of the viscous sticky event application scene, feel quite to force, here directly paste copied
User.java class:
// 实体类实现序列化publicclass User { String name ; String phoneNum; // 其他字段省略 publicUser(String aName) { name = aName ; } // 代码省略 }
First, the user class does not need to implement a serialization interface and avoids those boilerplate code. You can then publish the user object directly as a sticky event in mainactivity.
Public class mainactivity extends Activity { //One click event @Override Public void OnClick(View v) {User Auser =NewUser ("Mr.simple"); Auser.phonenum ="123456";//Other data //Post sticky eventsEventbus.getdefault (). Poststicky (Auser);//Jump to Profileactivity pageIntent Intent =NewIntent ( This, Profileactivity.class); StartActivity (Intent); }}
Finally, let's see how profileactivity receives the data.
Public class profileactivity extends Activity { @Override protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); Setcontentview (R.layout.activity_profile);//Register in sticky formEventbus.getdefault (). Registersticky ( This); }@Subscriber Private void Receiveuser(User info) {//Implement your logic here, info is the user object passed over}}
In profileactivity we register profileactivity itself as a subscriber to the bus, and Profileactivity receives the sticky event posted above, which is the user object. In this case, the Receiveuser function in profileactivity is triggered, and the info parameter is the user information object of the sticky event, which realizes its logic in Receiveuser.
Yes! We did not unregister subscribers in Ondestory, that is, we did not call Eventbus's unregister () function, which is one of the newest features and the only event bus library that does not require manual logoff at this time.
It is important to note that sticky sticky events require you to manually remove them!
Androideventbus new features: Add sticky events, do not need to manually unregister the event bus