显式跳转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);
Fragment跳转Activity:
getActivity().startActivity(new Intent(mContext,LabelBindingActivity.class));
网友评论