fpiaopiao

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  7 随笔 :: 0 文章 :: 0 评论 :: 656 阅读
Intent 意图,用于三大组件之间传递消息,可以理解为组件间传递消息的信使
 
打开百度:
复制代码
 1 public class UriActivity extends AppCompatActivity{
 2     Button uriBtn;
 3     @Override
 4     protected void onCreate(@Nullable Bundle savedInstanceState) {
 5         super.onCreate(savedInstanceState);
 6         setContentView(R.layout.activity_uri);
 7         uriBtn= (Button) findViewById(R.id.uriBtn);
 8         uriBtn.setOnClickListener(new View.OnClickListener() {
 9             @Override
10             public void onClick(View view) {
11                 //打开网页
12                 Intent intent=new Intent();
13                 intent.setAction(Intent.ACTION_VIEW);
14                 Uri data =Uri.parse("http://www.baidu.com");
15                 //利用Data属性
16                 intent.setData(data);
17                 startActivity(intent);
18             }
19         });
20     }
21 }
复制代码
Extras属性,是一个Bundle对象,用于封装数据,在组件之间传递数据,与map类型非常类似
复制代码
1 Bundle bundle = new Bundle();
2 bundle.putString("text", "I am a text");
3 Intent intent = new Intent(this, secondActivity.class);
4 intent.putExtras(bundle);
5 startActivity(intent);
复制代码
在secondActivity中,这样取得数据
1
2
Bundle bundle = this.getIntent().getExtras();
  String text = bundle.putExtras("text");

 

 

posted on   _fanfan  阅读(19)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示