Android Intent (initially enters intent)

Source: Internet
Author: User

In a project, it is composed of multiple Activity programs. At this time, communication between these Activity programs is required, and communication between these activities is completed by Intent. Intent operation method supported by the Activity program

No. Method Type Description
1 Public void startActivity (Intent intent) Normal Start an Activity and transmit data through Intent
2 Public void startActivityForResult (Intent intent, int requestCode) Normal Start and receive data from another Activity program. onActivityResult () can be triggered only when requestCode is greater than 0 ()
3 Public Intent getIntent () Normal Returns the Intent of the current Activity.
4 Protected void onActivityResult (int requestCode, int resultCode, Intent data) Normal This method is used to process the return operation when Intent data is returned.
5 Public void finish () Normal When this method is called, the previous Activity program is returned and the onActivityResult () method is automatically called.
6 Public final Cursor managedQuery (Uri uri, String [] projection, String selection, String [] selectionArgs, String sortOrder) Normal Processing the returned Cursor result set
The XML configuration file box JAVA file is as follows:
 
 
  
? The layout manager height is the screen height.
  ? Display text by default
  ? The component height is the text height.
 

Public class Send extends Activity {private Button mybut = null; // Button component private TextView msg = null; // Text Component @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); super. setContentView (R. layout. send_main); // default layout manager this. mybut = (Button) super. findViewById (R. id. mybut); // get the component this. msg = (TextView) super. findViewById (R. id. msg); // obtain the component this. mybut. setOnClickListener (New OnClickListenerImpl (); // defines the Click Event} private class OnClickListenerImpl implements OnClickListener {@ Overridepublic void onClick (View view) {Intent it = new Intent (Send. this, Receive. class); // instantiate Intentit. putExtra ("myinfo", "I plan to plan the utilities"); // Send additional information. this. startActivityForResult (it, 1); // start Activity }}@ Overrideprotected void onActivityResult (int requestCode, int resultCode, Intent data) {switch ( ResultCode) {// determine the operation type case RESULT_ OK: // The msg operation is successful. setText ("Returned content:" + data. getStringExtra ("retmsg"); break; case RESULT_CANCELED: // cancel the msg operation. setText ("Operation canceled. "); Break; default: break ;}}}


 
 
  
? The layout manager height is the screen height.
  ? The component height is the text height.
  ? Display text by default
 


Public class Receive extends Activity {private TextView show = null; // private Button retbut = null for the text display component; // Button component @ Overridepublic void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); super. setContentView (R. layout. receive_main); // call the default layout manager this. show = (TextView) super. findViewById (R. id. show); // obtain the component this. retbut = (Button) super. findViewById (R. id. retbut); // get the component Intent it = super. getIntent (); // get the IntentString info = it. getStringExtra ("myinfo"); // get the additional information for this setting. show. setText (info); // sets the text display information this. retbut. setOnClickListener (new OnClickListenerImpl (); // set listener} private class OnClickListenerImpl implements OnClickListener {@ Overridepublic void onClick (View view View) {Receive. this. getIntent (). putExtra ("retmsg", "HAHAHA"); // return information // set the status of the returned data, RESULT_ OK and Send. receive. this. setResult (RESULT_ OK, Receive. this. getIntent (); Receive. this. finish (); // end Intent }}}




Related Article

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.