3, the activity in the Android jump

Source: Internet
Author: User

1, create the project File->new->android application in turn fill in the application name, project name, package nameLocate Src/com.example.helloworld mainactivity.java2 in the project catalog, add code
Package Com.example.helloworld;import Android.app.activity;import Android.content.intent;import android.os.Bundle; Import Android.view.view;import Android.view.view.onclicklistener;import Android.widget.button;public class Mainactivity extends Activity {    private button button; @Overrideprotected void OnCreate (Bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main);   This.button = (Button) This.findviewbyid (r.id.button1);        This.button.setOnClickListener (New Onclicklistener () {            @Override public            void OnClick (View v) {                Intent Intent = new Intent ();                Intent.setclass (Mainactivity.this, intentactivity.class);                Intent.putextra ("name", "Hello World");                StartActivity (intent);}}        );}}

Before adding the code, in Res/layout/activity_main.xml, drag a button control up. The information for the button is automatically generated in the Activity_main.xml, note the ID value, and if you use this button, 3, add jump activity1, right click Src/com.example.helloworld,new->class, fill in the name intentactivity, do not add Java can2, add layout. Right-click on res/layout, new->android XML file, drag a textview on this XML. The TextView address is automatically added to the R.java in this case.3, add the following code in Androidmanifest.xml: Complete the activity registration
<activity android:name= "Com.example.helloworld.IntentActivity" > </activity>
4. Realize Intentactivity.java
Package Com.example.helloworld;import Android.app.activity;import Android.os.bundle;import Android.widget.TextView Import Android.content.intent;public class Intentactivity extends activity{@Overrideprotected void OnCreate (Bundle Savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_intent); Intent Intent = Getintent (); String string = Intent.getstringextra ("name"); TextView TextView = new TextView (this); Textview.settextsize (+); Textview.settext (string); Setcontentview (TextView);}}

4, run open simulator or mobile phone, run.

3, the activity in the Android jump

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.