https://github.com/coding-dream/eventbus
个人定制版EventBus,去除注解
https://github.com/coding-dream/eventbus
eventbus observable observer
Last synced: 5 months ago
JSON representation
个人定制版EventBus,去除注解
- Host: GitHub
- URL: https://github.com/coding-dream/eventbus
- Owner: coding-dream
- Created: 2016-12-23T06:02:37.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-23T03:26:18.000Z (over 8 years ago)
- Last Synced: 2025-04-07T09:03:39.323Z (6 months ago)
- Topics: eventbus, observable, observer
- Language: Java
- Homepage:
- Size: 145 KB
- Stars: 13
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## EventBus
带你一步步实现专属自己的事件总线,使用简洁,事件接收默认即为 UI线程去除原有EventBus注解功能,效率更好高
## 方式一
```
public class MainActivity extends AppCompatActivity implements Subscriber{private Subscriber subscriber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);EventBus.getDefault().register(this);
Intent intent = new Intent();
intent.setClass(this, TwoActivity.class);
startActivity(intent);}
@Override
protected void onDestroy() {
super.onDestroy();EventBus.getDefault().unregister(this);
}@Override
public void receive(Object object) {
Toast.makeText(MainActivity.this, subscriber + "Jam 收到消息了:" + object, Toast.LENGTH_SHORT).show();
}}
```
## 方式二
```
Subscriber subscriber = EventBus.getDefault().register(new Subscriber() {
@Override
public void receive(Object object) {
Toast.makeText(MainActivity.this, subscriber + "Tom 收到消息了:" + object, Toast.LENGTH_SHORT).show();
}
},"tag1");```
## 消息发送
```
public class TwoActivity extends AppCompatActivity {@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_two);EventBus.getDefault().notifyDataChange("fucking");
EventBus.getDefault().notifyDataChange("hello","tag1");}
}```