intent 传值

来源:互联网 发布:js取整 编辑:程序博客网 时间:2024/06/11 03:37

Intent参数传递

2011-9-21 08:59| 发布者: benben| 查看: 2755| 评论: 0

摘要: 当Activity与Activity/Service 参数传递,常用方法就是通过Intent实现例子:发送代码:Intentintent=newIntent(...);Bundlebundle=newBundle();bundle.putString("param","value");intent.putExtras ...

当Activity与Activity/Service 参数传递,常用方法就是通过Intent实现
例子:

发送代码:
  1. Intent intent = new Intent(...);  
  2. Bundle bundle = new Bundle();  
  3. bundle.putString("param""value");  
  4. intent.putExtras(bundle);  
  5. context.startActivity(intent); 或 context.startService(intent);  
接收代码:
  1. Bundle bunde = intent.getExtras();  
  2. String name = bunde.getInt("param");  


注意键值要一致。


0 0