Activity 和 Intent

一、实验目的

  1. 掌握Activity四种启动模式的特点
  2. 进一步掌握如何在Activity中添加控件并进行事件处理
  3. 理解隐式意图的使用
  4. 掌握如何通过Intent在多个Activity之间传递数据
  5. 掌握如何回传数据

三、代码展示 




Activity1.Java

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void click1(View view){
        Intent intent =new Intent(this,MainActivity.class);
        startActivity(intent);
        Log.i("Tag","页面一taskId:" + getTaskId());

    }
    public void click2(View view){
        Intent intent =new Intent(this,MainActivity.class);
        startActivity(intent);
        Log.i("Tag","页面二taskId:"+getTaskId());
    }
    public void click3(View view){
        Intent intent =new Intent(this,MainActivity.class);
        startActivity(intent);
        Log.i("Tag","页面三taskId:" + getTaskId());

    }
}
    
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

Activity2.java

public class Main2Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
    }
    public void click1(View view){
        Intent intent =new Intent(this,Main2Activity.class);
        startActivity(intent);
        Log.i("Tag","页面一taskId:" + getTaskId());

    }
    public void click2(View view){
        Intent intent =new Intent(this,Main2Activity.class);
        startActivity(intent);
        Log.i("Tag","页面二taskId:"+getTaskId());
    }
    public void click3(View view){
        Intent intent =new Intent(this,Main2Activity.class);
        startActivity(intent);
        Log.i("Tag","页面三taskId:" + getTaskId());
    }
}

    
    
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25


public class Main3Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);
    }
    public void click1(View view){
        Intent intent =new Intent(this,Main3Activity.class);
        startActivity(intent);
        Log.i("Tag","页面一taskId:" + getTaskId());

    }
    public void click2(View view){
        Intent intent =new Intent(this,Main3Activity.class);
        startActivity(intent);
        Log.i("Tag","页面二taskId:"+getTaskId());
    }
    public void click3(View view){
        Intent intent =new Intent(this,Main3Activity.class);
        startActivity(intent);
        Log.i("Tag","页面三taskId:" + getTaskId());
    }
}



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值