In the OnCreate () method of the main activity, by Findviewbyid the defined components in the Activiity_main, such as button, EditText, etc., note the need to force a transition view to a specific type.
Adds a listener such as Onclicklistener () to the acquired component BTN, where the intent object is instantiated, and the argument is the departure class and the target class to jump.
Add content to the intent object with the Putextra () method, with the contents k-v pairs. A writable mark in K, in which the content to be transmitted is stored in V.
public void OnClick (View arg0) { //.class method is used Intent intent1 = new Intent (act,jumpactivity.class); Intent1.putextra ("TestKey", "gaozy");//enable the intent to implement Jump Act.startactivity (INTENT1);}
In targetactivity, use Getintent () to obtain the intent defined in the main activity by Getxxxxextra (K) (XXX depends on the data type) for the value
public void Onresume () {super.onresume ();//Why can the direct getintent (), can also have multiple intent exist? can automatically detect intent that point to this class? Intent intent=getintent ();//The value of the key obtained here is equivalent to that of the previous main activity? has been confirmed. Key = Intent.getstringextra ("TestKey");//context's role. The Toast.show method makes the toast effective//How to use the method under Toast, custom position, with picture, etc., with Toast Instance report cannot find Activity//toast.setgravity (gravity.center, 0, 0); Toast.maketext (this, key, Toast.length_long). Show ();
Toast Validation.