I dream a dream.

There are some ways to declare a new activity in android. But in this section, I just want to describe an simplest way to do it.

– Open the AndroidManifest.xml file then follow below steps to add new activity.

image

– Look at the Attributes for Activity section at right side, click Name to create a new class or Browse to choose an existing class. This class will contain code-behind of this activity and it must inherit from Activity class under android.app.Activity namespace. Also you can configure other properties for you activity such as orientation, theme, label…

image

– Right click on Layout folder, choose new > Android XML File. In the new Android XML File dialog, type the class name then hit button Finish. Note that the layout file name must end with “.xml” and just contains a-z, 0-9 character.

image

– Open MyActivity.java file, edit the OnCreate method as below image.

image

Now, whenever MyActivity is invoked, it load the myactivity.xml layout to the screen.

 

The End.

Advertisements

Comments on: "Declare new activity in android" (1)

  1. […] you don’t know how to add an activity, please read my post here. Suppose that you created an activity name MyActivity. Now, open AndroidManifest.xml file, choose […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: