Intent on Android Two page value problem

Source: Internet
Author: User

Android intent on two pages there are two main values, one is to pass values between two activity, and the other is to pass data between a normal page and an activity.

1. Intent values between two activity

first define two activity firstactivity and secondactivity

Code in the OnCreate () method of firstactivity

Intent Intent = new Intent ();

String str = "Data to be passed";

Intent.putextra ("str", str);

Intent.setclass (firstactivity. this, secondactivity.class);
StartActivity (Intent);

In the Secondactivity page

Intent Intent = Getintent ();

Intent.getstringextra ("str");

2. Intent passing data between a normal page and an activity

two pages of mainactivity and Intention.java respectively

Code in the OnCreate () method of mainactivity

Intent Intent = new Intent ();

String str = "Data to be passed";

Intent.putextra ("str", str);

Intent.setclass (context, secondactivity.class);
Context. startactivity (intent);

The code in Intention.java is

Intent Intent = Getintent ();

Intent.getstringextra ("str");

Original address: http://www.bkjia.com/qtjc/614274.html

Intent on Android Two page value problem

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.