- 显式跳转和隐式跳转
- Activity之间的数据传递
- startActivityForResult:启动Activity,结束后返回结果
显式跳转和隐式跳转
package com.example.test0508.jump;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import com.example.test0508.R;
public class AActivity extends AppCompatActivity {
private Button mBtnJump1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_a);
/**
* 显式跳转,从A跳到B
* 方法一
*/
mBtnJump1 = findViewById(R.id.btn_jump1);
mBtnJump1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(AActivity.this,BActivity.class);//从Activity.this跳到B.class
startActivity(intent);
}
});
/**
* 显示的第二个办法
*
Intent intent = new Intent();
intent.setClass(AActivity.this,BActivity.class);
startActivity(intent);
*/
/**
* 显示跳转的第三个方法
Intent intent = new Intent();
intent.setClassName(AActivity.this,"com.example.test0508.jump.BActivity");
startActivity(intent);
*/
/**
* 显示跳转的第四个方法
Intent intent = new Intent();
intent.setComponent(new ComponentName(AActivity.this,"com.example.test0508.jump.BActivity"));
startActivity(intent);
*/
/**
* 隐式调用1
Intent intent = new Intent();
intent.setAction("com.example.test0508.test.BActivity");
startActivity(intent);
*/
}
}
Activity之间的数据传递
AACtivity
package com.example.test0508.jump;
import androidx.appcompat.app.AppCompatActivity;
import android.content.