显式跳转1:
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
startActivity(intent);
显式跳转2:
Intent intent =new Intent();
intent.setClass(FirstActivity.this,SecondActivity.class);
startActivity(intent);
显示跳转3:
Intent intent = new Intent();
intent.setClassName(FirstActivity.this,"com.example.lineralayout.jump.SecondActivity");
startActivity(intent);
显式跳转4:
Intent intent = new Intent();
intent.setComponent(new
ComponentName(FirstActivity.this,"com.example.lineralayout.jump.SecondActivity"));
startActivity(intent);
隐式跳转1:
//Manifest文件
<activity android:name=".jump.SecondActivity"
android:label="Second">
<intent-filter>
<action android:name="com.intent.test.SecondActivity" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
//activity代码
Intent intent = new Intent();
intent.setAction("com.intent.test.SecondActivity");
startActivity(intent);
数据传递:
第一个Activity:
//显式跳转1
Intent intent = new Intent(FirstActivity.this,SecondActivity.class);
Bundle bundle = new Bundle();
bundle.putString("name","小王");
bundle.putInt("number",25);
intent.putExtras(bundle);
startActivity(intent);
第二个Activity:
mTv = findViewById(R.id.tv_title);
Bundle bundle = getIntent().getExtras();
String name = bundle.getString("name");
int number = bundle.getInt("number");
mTv.setText(name+","+number);
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦