Intent four types of jumps showing intent

Source: Internet
Author: User

There are four kinds of intent common
1, first in the mainactivity to establish a button class B,
Then use Setcontentview (R.layout.activity_main) to find the button,
Let B = (Button) setcontentview (R.layout.activity_main);
Add Mouse events for B
B.setonclicklistener (this); To implement the implements Onclicklistener interface at this time
Implementing the OnClick method
public void OnClick (View v)
{
Definition Intent Intent = new intent ();
Intent.setclass (This,activity_01.class);

SetClass (Need a onclicklistener, at this time we inherit the interface so write this, need to jump class bytecode file with. class knot);

Last write Start method;
StartActivity (Intent);
}


2, public void OnClick (View v)
{
Definition Intent Intent = new intent ();
Intent.setclassname (This, "com.example.intentdemo.Activity_01");

Setclassname (this, requires a string to jump to the full class name of the activity);

Last write Start method;
StartActivity (Intent);
}

3,public void OnClick (View v)
{
Definition Intent Intent = new intent ();
Intent.setclassname ("com.example.activity", "activity.") Activity_01 ");

Setclassname (requires XML package name, to jump activity of the full class name);

If you want to jump to other non-main interface activity, you need to configure Android:exported= "true" in XML
The default value is False

Last write Start method;
StartActivity (Intent);
}
4,public void OnClick (View v)
{
Definition Intent Intent = new intent ();
Intent.setcomponent (New ComponentName (This,activity_01.class));

Intent.setcomponent (Requires ComponentName object, new one componentname required (this, byte code to jump));

Last write Start method;
StartActivity (Intent);
}

Intent four kinds of jumps

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.