Android static parameter passing
1. Create OtherActivity. java
public class OtherActivity extends Activity {public static String name;public static int age;private TextView textview;protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.other); textview = (TextView)this.findViewById(R.id.msg); textview.setText("name:"+name+",age:"+age); }}
Defines the static variable name, age.
Ii. In MainActivity. java, when you jump to the page, call the static variable name and age of class OtherActivity to pass in
public class MainActivity extends Activity {Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button = (Button)this.findViewById(R.id.button1); button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {// TODO Auto-generated method stubIntent intent = new Intent();intent.setClass(MainActivity.this,OtherActivity.class);OtherActivity.age = 23;OtherActivity.name ="deng";startActivity(intent);}}); }}
3. Attach xml
1) activity_main.xml
2) other. xml
3)AndroidManifest.xml