In Activity, Intent is used to implement page Jump and parameter transfer. activityintent

Source: Internet
Author: User

Use Intent in Activity to implement page Jump and parameter transfer (conversion), activityintent

Create a firstavti.pdf. java

Package com. zhuguangwei; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. view. view; import android. view. view. onClickListener; import android. widget. button; public class FirstActivity extends Activity {private Button myButton;/** Called when the activity is first created. * // @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. main); myButton = (Button) findViewById (R. id. myButton); myButton. setOnClickListener (new OnClickListener () {@ Overridepublic void onClick (View v) {// TODO Auto-generated method stubIntent intent = new Intent (); // Intent transmits the intent parameter. putExtra ("testIntent", "123"); intent. setClass (FirstActivity. this, SecondActivity. class); FirstActivity. this. startActivity (intent );}});}}

Create the second SecondActivity. java

Package com. zhuguangwei; import android. app. activity; import android. content. intent; import android. OS. bundle; import android. widget. textView; public class SecondActivity extends Activity {private TextView myTextView; @ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentView (R. layout. other); // use the Intent object to get the Intent intent parameter passed by FirstActivity = getIntent (); String value = intent. getStringExtra ("testIntent"); myTextView = (TextView) findViewById (R. id. myTextView); myTextView. setText (value );}}

Both activities must be registered in AndroidMenifest. xml.

(

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.