android - activity 之间传递参数 intent

访问量: 140

参考:https://www.cnblogs.com/tinyphp/p/3840257.html

    //新建一个显式意图,第一个参数为当前Activity类对象,第二个参数为你要打开的Activity类
    Intent intent =new Intent(MainActivity.this,MainActivity2.class);
    
    //用Bundle携带数据
    Bundle bundle=new Bundle();
    //传递name参数为tinyphp
    bundle.putString("name", "tinyphp");
    intent.putExtras(bundle);
    
    startActivity(intent);        
    }



// activity 2

 protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.newtest);   
        
        //新页面接收数据
        Bundle bundle = this.getIntent().getExtras();
        //接收name值
        String name = bundle.getString("name");
       Log.i("获取到的name值为",name);     
    } 

订阅/RSS Feed

Subscribe

分类/category