安卓中intent切换界面与传递数值

在安卓中,经常用Intent来传递数值和对象,现在来介绍下intent的用法:
首先是 Activity1:

 Intent intent = new Intent();  // Activity1
        intent.putExtra("one", num1);  
        intent.putExtra("two", num2);  
        intent.setClass(FirstActivity.this, SecondActivity.class);  
            startActivity(intent);

然后 Activity2来接受传过来的数值

Intent intent = getIntent();  //Activity2
    String num1 = intent.getStringExtra("one");  
    String num2 = intent.getStringExtra("two");  

方法2:

 Intent intent =new  Intent(AActivity.this,BActivity.class);
   intent.putExtra("num1", num1) ;
   intent.putExtra("num2", num2) ;
   startActivity(intent) 

接受方:

String num1 =this.getIntent().getStringExtra("num1") ; 
 String num2 =this.getIntent().getStringExtra("num2") 

你可能感兴趣的:(android,对象,intent)