第一个Activity:
package com.example.wjb.myapplication; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button btn = (Button) findViewById(R.id.button); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent i = new Intent(MainActivity.this, Act.class); i.putExtra("data", "Hello world"); startActivity(i); } }); } }
第二个Activity:
package com.example.wjb.myapplication; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.widget.TextView; /** * Created by wjb on 2015/9/2. */ public class Act extends Activity{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act); TextView tv= (TextView) findViewById(R.id.textView); Intent i = getIntent(); tv.setText(i.getStringExtra("data")); } }