Android Learning Note Three: Intent implementation page Jump

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.