First, the new Otheractivity.java
public class Otheractivity extends Activity {<span style= "color: #ff0000;" >public static String name;public static int age;</span>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.
Second, in Mainactivity.java, jump page when the static variable called Class Otheractivity name, the age parameter passed 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); <span style= "color : #ff0000; " >otheractivity.age = 23;otheractivity.name = "Deng"; </span>startactivity (Intent);}});} }
Third, attach XML
1) activity_main.xml
<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http// Schemas.android.com/tools " android:layout_width=" match_parent " android:layout_height=" Match_parent " android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=". Mainactivity "> <button android:id=" @+id/button1 " android:layout_height=" Wrap_content " Android:layout_width= "Match_parent" android:text= "static variable pass parameter test" /></relativelayout>
2) Other.xml
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "vertical" > <textview android:id= "@+id/msg" android:layout_width= "Match_parent" android:layout_height= "Wrap_content" > </TextView></LinearLayout>
</pre><pre code_snippet_id= "620199" snippet_file_name= "blog_20150315_6_982152" name= "code" class= "HTML" >3) Androidmanifest.xml
<pre name= "code" class= "HTML" ><?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "/http Schemas.android.com/apk/res/android "package=" com.example.intent_static "android:versioncode=" 1 "android:versionn Ame= "1.0" > <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/> <applicat" Ion android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name" Android:theme= "@style/apptheme" > <activity android:name= "com.example.intent_static. Mainactivity "android:label=" @string/app_name "> <intent-filter> <action Android:name= "Android.intent.action.MAIN"/> <category android:name= "Android.intent.category.LAUNCHER "/> </intent-filter> </activity> <activity android:name=". Otheractivity "/> </applicaTion></manifest>
Android static transmission parameters (V)