Android app activity parameters and redirection

Source: Internet
Author: User

Http://mobile.51cto.com/android-265546.htm

Acitvity Development

A. Configuration File

 
  1. <activity android:name=".OtherActivity" android:label="otherActivity"> 
  2. </activity> 

B. Write layout files

C. Write a class to inherit the activity and override oncreate. In this method, set the layout file.Setcontentview (R. layout. Other );

Activity Parameters// Method 1 for passing parameters with Intent

// Intent. putextra ("name", "Tan Jianping ");
// Intent. putextra ("Age", 25 );

// Method 2

Bundle bundle = new bundle (); bundle. putstring ("name", "Tan Jianping ");

Bundle. putint ("Age", 25); intent. putextras (bundle );

Intent intent = This. getintent ();

// Get the meaning of activating the account

// Method 1 obtain the parameter string name = intent. getstringextra ("name"); int age = intent. getintextra ("Age", 0 );

// Obtain parameters in method 2

Int age = intent. getextras (). getint ("Age ");
String name = intent. getextras (). getstring ("name ");

Set the component to be activated

 Intent intent = new intent (mainactivity. This, otheractivity. Class );

// Set the component to be activated for intent

// Statement 1: intent. setclass (mainactivity. This, otheractivity. Class );

// Set the component to be activated

// Statement 2: intent. setcomponent (New componentname (mainactivity. This, otheractivity. Class ));

// Set the component to be activated

When an opened activity is closed, the following method is used to open the activity:

 
  1. Startactivityforresult (intent, 10); // is the request 10 when the opened intent is disabled?

Intent intent2 = new intent (); intent2.putextra ("result", "this is the result of disabling returned"); setresult (10, intent2 ); // 10 is the return code finish (); // close the activity

Override of opened Activity

 
  1. /**
  2. * When an opened activity is disabled
  3. * Requestcode Request Code
  4. * Resultcode return code
  5. * The Request Code and return code are used to differentiate multiple activities during a jump.
  6. */
  7. @ Override
  8. Protected void onactivityresult (INT requestcode, int resultcode, intent data ){
  9. Toast. maketext (this, Data. getstringextra ("result"), Toast. length_short). Show ();
  10. Super. onactivityresult (requestcode, resultcode, data );
  11. }

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.