Android Intent Jump

Source: Internet
Author: User

One, does not need to return the value the jump

Intent intent=new Intent ();

Intent.setclass (current acitivy.this, Target activity.class);

StartActivity (Intent);

Second, a jump that needs a return value

Intent intent=new Intent ();

Intent.setclass (current acitivy.this, Target activity.class);

StartActivity (Intent);

Startactivityforresult (Intent, status value (int type));

The status value is used as a validation of the accepted target return value.

Requestcode receive the returned status value

RESULTCODE:RESULT_OK Result_canceled can assign its own value, press the return key, the system default assignment is: result_canceled

Target activity closed to return request activity

For example:

1. Request page

public class Mainactivy extends Activity {

@Override
public void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Intent intent=new Intent ();
Intent.setclass (Mainactivy.this, Receivemsg.class);
Startactivityforresult (Intent, 0);
}

protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
TODO auto-generated Method Stub
Super.onactivityresult (Requestcode, ResultCode, data);
if (requestcode==0) {
if (RESULTCODE==RESULT_OK) {
Toast.maketext (This, "Send SMS result_ok", Toast.length_short). Show ();
}else if (resultcode==result_canceled) {
Toast.maketext (This, "result Cancel", Toast.length_short). Show ();
}else {
Toast.maketext (This, ResultCode, Toast.length_short). Show ();
}
}else {
Toast.maketext (This, "Requsetcode not 0", Toast.length_short). Show ();
}

}
}

2. Receive the return value interface

public class Receivemsg extends activity{

    protected void OnCreate (Bundle savedinstancestate) {
         //TODO auto-generated Method stub
         Super.oncreate (savedinstancestate);         
         receivemsg.this.setresult (RESULT_OK);
        this.finish ();       
    }
}

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.