Android New Activity Method _android

Source: Internet
Author: User

The example in this article describes how Android creates a new activity. Share to everyone for your reference, specific as follows:

How do you create a new activity in an Android project? The method is as follows:

One, create a new Class (*.class), inherit from Android.app.Activity class.

Second, create a new layout XML file in the Res/layout directory, the file name is free (only lowercase alphanumeric or underlined), used to set the layout of the new activity (for how to set the layout of the activity, you can refer to the site related content).

Third, open the Androidmanifest.xml file, in the inside to carry out the registration of new activity.
By double-clicking the Androidmanifest.xml file, this option appears below the editing area of Eclipse:

Select Application This option to drag the edit area's scroll bar to the bottom and find:

Currently there are activity in the main activity, we click the Add button, select activity, then you will find the above application nodes more than one activity, click on the left of the new activity, make sure it is selected, Then click on the name item in the attributes for activity on the right, and enter the name of the new activity in the pop-up dialog box (the class name of the class you created first), it has automatic lookup when you enter the name, and then click Save, The new activity is registered, and we can also see the newly registered activity (you can also add code directly) from the Androidmanifest.xml code.

Then go to the class you built first, add the OnCreate method to the new activity in the class, adding:

@Override public
  void OnCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (r.layout.show_info_activity); Show_info_activity is the second step the file name of the newly created XML file
  }

Such an activity would have been created.

The shift in activity is also very simple. With intent can be achieved, interested friends can refer to the site intent relevant information.

For more information on Android-related content readers can view the site: "The activity of Android programming skills Summary", "Android Communication method Summary", "Android debugging techniques and common problems solution summary", " Android Introduction and advanced tutorials, summary of Android Basic components usage, Android layout layout tips and a summary of Android controls usage

I hope this article will help you with the Android program.

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.