Android_EventBus
来源:互联网 发布:sql server2012向导 编辑:程序博客网 时间:2024/06/05 05:53
代码块:
public class MainActivity extends AppCompatActivity { EventBus bus; ProgressBar progressBar; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); bus=EventBus.getDefault(); bus.register(this); progressBar = (ProgressBar) findViewById(R.id.progressbar); } public void click(View view){ /*bus.post("我就是EventBus发送的消息"); */ Intent intent=new Intent(this,Main2Activity.class); startActivity(intent); } @Subscribe(threadMode = ThreadMode.MAIN) public void MyThread(String par){ Log.i("aaa","aa:"+par); Toast.makeText(MainActivity.this,"第一个页面的:"+par,Toast.LENGTH_SHORT).show(); } @Override protected void onDestroy() { super.onDestroy(); bus.unregister(this); }}
public class Main2Activity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main2); } public void click(View view){ EventBus.getDefault().post("我来了"); finish(); }}
布局:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:orientation="vertical" tools:context="org.frxm.eventbus.MainActivity"> <ProgressBar android:id="@+id/progressbar" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="150dp" android:max="100" android:progress="0" style="?android:progressBarStyleHorizontal"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="发送消息" android:onClick="click"/></LinearLayout>
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main2" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="org.frxm.eventbus.Main2Activity"><Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="click" android:text="发送"/></RelativeLayout>
阅读全文
0 0
- Android_EventBus
- Android_EventBus使用
- android_EventBus入门学习笔记
- Android_EventBus简单传值
- Android_EventBus的使用和源码分析
- Android_eventbus第三方库_EventBus的使用
- deeplearning-Regularization
- Java基础------构造器
- poj1679 The Unique MST
- Spark之分区
- android通过反射来获取系统属性SystemProperties
- Android_EventBus
- 致——世界上最幸福的女孩——Chtholly
- HDU
- poj1789 Truck History
- GenericServlet抽象类以及过滤器
- 1213: [视频]【计算几何】面积
- maven 下载、安装、配置详解
- Spark之join
- MySQL索引类型总结和使用技巧以及注意事项