Android entry-Activity

Source: Internet
Author: User

Activity

1. Role

Control container

2. Create an activity
2.1 inherit the activity class
2.2 rewrite the oncreate method (the first operation will be called in the window)
2.3 Register in mainifest. xml
2.4 Add controls

Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity_main );

Textview TV1 = (textview) findviewbyid (R. Id. textview1 );
Tv1.settext ("Hello kllmctrrl hello! ");

}

3. Activity and intent

3.1 page Jump
Activity01.startactivity (intent) Method

3.2 intent object
Component name --> activity/service...
Action --> fun
Data --> data
Extras -->
...

// Main
Button btn1 = (button) findviewbyid (R. Id. button1 );
Btn1.settext ("Press ");
Btn1.setonclicklistener (New buttonlistener ());

// Listener
Class buttonlistener implements onclicklistener {

@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Intent intent = new intent ();
Intent. setclass (mainactivity. This, otheractivity. Class );
Intent. putextra ("tag", "123 ");
Mainactivity. This. startactivity (intent );
}
}

// Other
Textview TV1 = (textview) findviewbyid (R. Id. textview2 );
Intent intent = getintent ();
Tv1.settext (intent. getstringextra ("tag "));

// OthersProgramActivity

Uri uri = URI. parse ("smsto: // 020 ");
Intent intent = new intent (intent. action_sendto, Uri );
Intent. putextra ("sms_body", "SMS text ");
Startactivity (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.