EventBus is a publish/subscribe event bus optimized for Android.
創(chuàng)新互聯(lián)-云計(jì)算及IDC服務(wù)提供商,涵蓋公有云、IDC機(jī)房租用、四川電信機(jī)房托管、等保安全、私有云建設(shè)等企業(yè)級互聯(lián)網(wǎng)基礎(chǔ)服務(wù),聯(lián)系電話:028-86922220so make it simple,just think EventBus as a framework that allow different compoents to communicate,
usually a subscribe register a certain event,then whenever a publisher has post an event,any subscribes who had register this event will be able to receive the notify.
This is an example,Let's say MainActivity is a subscribe who has register to receive RecvEvent event,
And Second Activity is a publicer who will post a RecvEvent when his btn is clicked.Theoretically speaking,MainActivity is able to recevie the event that posted by SecondActivity.
//From above,we know that EventBus contains three objects:Event,Subscribe,Publisher
//Event public class RecvEvent { private final String info; public RecvEvent(String info) { this.info = info; } public String getInfo() { return info; } } //Subscribe:MainActivity public class MainActivity extends AppCompatActivity { private TextView tvShowInfo; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvShowInfo = (TextView)findViewById(R.id.tvShowRecv); //register to recevie ShowRecvEvent event EventBus.getDefault().register(this); } @Override protected void onDestroy() { super.onDestroy(); //destroy res EventBus.getDefault().unregister(this); } @Subscribe(threadMode = ThreadMode.MAIN) public void onRecvEvent(ShowRecvEvent event) { tvShowInfo.setText(event.getInfo()); } public void onJump(View view) { startActivity(new Intent(this,SecondActivity.class)); } } //publisher:SecondActivity public class SecondActivity extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.second_activity); } public void onSend(View view) { EventBus.getDefault().post(new ShowRecvEvent("this is from second activity")); } }
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。