zoukankan      html  css  js  c++  java
  • Android:EventBus

    public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    EventBus.getDefault().register(this);
    }


    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(InfoBean info) {//根据参数类型来接受,只要是这个类型的参数都会接受到.

    String msg = "onEventMainThread收到了消息:" + info.getInfo();
    Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
    }

    public void start(View view){
    Intent intent=new Intent();
    intent.setClass(getApplicationContext(),SecondActivity.class);
    startActivity(intent);
    }

    @Override
    protected void onDestroy() {
    super.onDestroy();
    EventBus.getDefault().unregister(this);//反注册EventBus
    }
    }

    public class SecondActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_second);
    }
    public void sendMes(View view){
    EventBus.getDefault().post(new InfoBean("我是回传的数据"));
    }
    }

    dependencies {
        compile fileTree(include: ['*.jar'], dir: 'libs')
        androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
            exclude group: 'com.android.support', module: 'support-annotations'
        })
        testCompile 'junit:junit:4.12'
        compile 'com.android.support:appcompat-v7:24.2.1'
        compile 'org.greenrobot:eventbus:3.0.0'
        compile 'com.wx.wheelview:wheelview:1.3.3'//这个是测试滚动的依赖
    }
  • 相关阅读:
    WPF进程之间通讯
    win7切换到classic主题后,控件问题
    How to host win32 in wpf?
    WPF 个人经验总结:需要注意的地方
    ListView 的三种数据绑定方式
    用DebugVIew 跟踪调试WPF
    屏幕变小后,wpf窗口被截掉的问题。
    WPF中DPI 的问题
    css中元素居中总结
    arcmap vba 根据DEM高程值生成Shp高程字段
  • 原文地址:https://www.cnblogs.com/tinyclear/p/6227030.html
Copyright © 2011-2022 走看看