I'm here there are two Windows the second window will pass the first window to the value displayed on the second window of the button is destroyed this window the first window button is loaded in the second window and passed the value to the second window (there are several button ID and TextView ID I will not mention should understand)
This is mostly used by intent to find out how much this object uses.
This is the Java code for the first window mainactivity
Package Com.example.vmpdump.windw;import Android.content.intent;import android.support.v7.app.AppCompatActivity; Import Android.os.bundle;import Android.view.view;import Android.widget.button;public class MainActivity extends appcompatactivity {@Override protected void onCreate (Bundle savedinstancestate) {super.oncreate (Savedinstan Cestate); Setcontentview (R.layout.activity_main); Button Bt=findviewbyid (R.id.button); Bt.setonclicklistener (Onclicklistener); } private View.onclicklistener Onclicklistener =new View.onclicklistener () {@Override public void oncli CK (view view) {Intent Intent =new Intent (); Intent.setclass (Mainactivity.this,main2activity.class);//The first is the current window context second is to load the window class Intent.putextra ("key", "haha haha" );//pass parameter key value pair to another window equivalent to map can pass array, object what serializable this is the startactivity of the object (intent);//Start intent//If you is the window generated directly with the IDE manifest without adding <activity android:name= ". Main2activity android:label= "Window caption" ></activity> he automatically added};}
This is the second window of Java class code main2activity
Package Com.example.vmpdump.windw;import Android.content.intent;import android.support.v7.app.AppCompatActivity; Import Android.os.bundle;import android.view.view;import android.widget.button;import Android.widget.TextView; public class Main2activity extends Appcompatactivity { @Override protected void OnCreate (Bundle Savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main2); Intent Intent =getintent (); Bundle Bundle=intent.getextras (); String temp= bundle.getstring ("key"); TextView textview= Findviewbyid (r.id.lab); Button Button=findviewbyid (r.id.button2); Button.setonclicklistener (Onclicklistener); Textview.settext (temp); } Private View.onclicklistener onclicklistener=new View.onclicklistener () { @Override public void OnClick ( View view) {finish ();//Destroy this window to automatically return to the loading window} };
How to load a new window in Android How to close a window and pass a value to another window