Android Learning Path--------Intent

Source: Internet
Author: User

Formally began to learn Android, no reading and video, so there is no systematic study, just see which knowledge points to learn, today learning interface between the jump, as well as the value, the main point of knowledge is intent,

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
LinearLayout view = new LinearLayout (Getapplicationcontext ());
Setcontentview (view);
Settitle ("This is an activity");
Button button = New button (Getapplicationcontext ());
Button.settext ("Click I jump to the next screen");
View.addview (button);
Button.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View arg0) {
Intent Intent = new Intent ();
Intent.setclass (Getapplicationcontext (), activitytest1.class);
Intent.putextra ("Key", "11");
Startactivityforresult (Intent, 1);
}
});
}

SetClass indicates which page to jump to, PutExtra represents the value to be passed to the next interface, similar to the Key,value method.

StartActivity () just jump to the target page, if you want to jump back to the current page, you must use the startactivity () again;

This task can be done one time, when the program executes to this code, if from T1activity jump to the next text2activity, and when the text2activity call the Finish () method, the program will automatically jump back t1activity , and call the Onactivityresult () method in the previous t1activity.

@Override
protected void Onactivityresult (int requestcode, int resultcode, Intent data) {
Super.onactivityresult (Requestcode, ResultCode, data);
System.out.println (requestcode+ ":::: Requestcode");
System.out.println (resultcode+ ":::: ResultCode");
if (Requestcode = = ResultCode) {
Bundle bundle = Data.getextras ();
String param = bundle.getstring ("active1");
Settitle (param);
}
}

An additional interface

@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (r.layout.second_activity);
LinearLayout view = new LinearLayout (Getapplicationcontext ());
Setcontentview (view);
Bundle bundle = Getintent (). Getextras ();
if (bundle! = null) {
Settitle ("Main Interface" +bundle.getstring ("key"));
}
Button button = New button (Getapplicationcontext ());
Button.settext ("Click I jump to the previous screen");
View.addview (button);
Button.setonclicklistener (New Onclicklistener () {

@Override
public void OnClick (View arg0) {
Bundle bundle = new bundle ();
Bundle.putstring ("active1", "This is the data transmitted by the Activity1");
Intent Intent = new Intent ();
Intent.putextras (bundle);
Setresult (1,intent);
Finish ();
}
});
}

Android Learning Path--------Intent

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.