Android Development notes (8) -- Call sub-Activity, androidactivity

Source: Internet
Author: User

Android Development notes (8) -- Call sub-Activity, androidactivity
Reprinted Please note: http://www.cnblogs.com/igoslly/p/6853730.html

 Call a sub-Activity 

The return value of a child Activity is required. MainActivity uses startActivityForResult Method
The return value of a child Activity is not required. MainActivity uses startActivity Method
MainActivity Set intent. putExtras directly

MainActivity When passing values:
Intent intent = new Intent (MainActivity. this, subActivity. class); intent. putExtra ("value_key", transmitted value)

 

Value_key is a value tag agreed by the developer. It can be obtained through getIntExtra in the sub-Activity (when transmitted as int ). PutExtra can transmit multiple types of values, but the get function is slightly different.
Intent intent = getIntent();intent.getIntExtra(“value_key”,0);

 

The sub-function obtains the corresponding value based on the different labels set for each value. When startActivityForResult is used
Intent intent =new Intent(MainActivity.this,subActivity.class);startActivityForResult(intent,0x1001);

 

0x1001 is the custom request code. In the sub-Activity, setResult () is used to set the return value. 
Intent. intent = new Intent (); intent. putExtra ("revalue_key", return value); setResult (0x1001, intent );
When the child Activity is disabled, MainActivity starts the onActvityResult method. 
@overridesuper.onActivityResult(requestCode,resultCode,data){       if(requestCode==0x1001){           String str =data.getStringExtra(“revalue_key”);}        }
RequestCode is the promoter Activity. resultCode displays the running results of the sub-Activity, usually Activity. RESULT_ OK (normal) and Activity. RESULT_CANCELLED (abnormal shutdown); data is returned by an Intent package. Statement:

1. The text and pictures in this note are both original and original. For reprinted documents, enter "blog garden-igoslly ".

2, Android development courses in 2017 4 years to participate in Google developer learning, notes original http://www.studyjamscn.com/thread-20580-1-1.html#pid272486

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.