Android中Message参数传递
16lz
2021-12-04
public class MainActivity extends Activity { final static int CANSHU = 1; public Handler mHandler=new Handler(){ public void handleMessage(Message msg) { switch(msg.what){ case CANSHU : String str1 = msg.getData().getString("text1");//接受msg传递过来的参数 String str2 = msg.getData().getString("text2");//接受msg传递过来的参数 initFinishMainActivity(str1, str2); break; default : break; } } }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); InitMainActivity(); }
//Message使用bundle传递参数: public void send() { Message msg = new Message(); msg.what = MainActivity.CANSHU; Bundle bundle = new Bundle(); bundle.putString("text1","大明的消息传递参数的例子!"); //往Bundle中存放数据 bundle.putString("text2","Time:2016-11-03"); //往Bundle中put数据 msg.setData(bundle);//mes利用Bundle传递数据 activity.mHandler.sendMessage(msg);//用activity中的handler发送消息 }
}
更多相关文章
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- python起点网月票榜字体反爬案例
- Python技巧匿名函数、回调函数和高阶函数
- python list.sort()根据多个关键字排序的方法实现
- android http-post方法简单实现
- android工具详解
- 通过CMD 查看android APP数据库表
- android 上中文排序
- Android之SQLLite