80

In Eclipse you just clicked the new button and select the android activity to add new activity. But Android Studio is a bit diferent; I couldn't find out how to add new activity to the project.

0

8 Answers 8

128

To add an Activity using Android Studio.

This step is same as adding Fragment, Service, Widget, and etc. Screenshot provided.

[UPDATE] Android Studio 3.5. Note that I have removed the steps for the older version. I assume almost all is using version 3.x.

enter image description here

  1. Right click either java package/java folder/module, I recommend to select a java package then right click it so that the destination of the Activity will be saved there
  2. Select/Click New
  3. Select Activity
  4. Choose an Activity that you want to create, probably the basic one.

To add a Service, or a BroadcastReceiver, just do the same step.

7
  • 6
    I had to go src > main > java > com.example.myapp > right click > New > Android Component.
    – Robert
    Commented May 25, 2013 at 12:54
  • 1
    Is there a way to create an activity from an existing Layout XML resource? Commented Nov 20, 2014 at 20:10
  • Ok, this is how to create new activity, but how to display layout of new activity?
    – user198003
    Commented Dec 13, 2014 at 7:26
  • @user198003 when you create new activity AS will create layout for you.
    – Glenn
    Commented Dec 13, 2014 at 12:33
  • This way Android Studio forces me to create a new layout file as well. How can I achieve this if the corresponding layout file already exists? I want to associate the new activity being added to an already existing layout file.
    – RBT
    Commented Aug 19, 2018 at 0:15
22

In Android Studio 2, just right click on app and select New > Activity > ... to create desired activity type.

enter image description here

0
5

I think natually do it is straightforward, whether Intellij IDEA or Android Studio, I always click new Java class menu, and then typing the class name, press Enter to create. after that, I manually typing "extends Activity" in the class file, and then import the class by shortcut key. finally, I also manually override the onCreate() method and invoke the setContentView() method.

1

In Android Studio, go to app -> src -> main -> java -> com.example.username.projectname

Right click on com.example.username.projectname -> Activity -> ActivityType

Fill in the details of the New Android Activity and click Finish.

Viola! new activity added to the existing project.

0

In Android Studio, go to app --> src --> main --> res-->

File --> new --> Activity --> ActivityType [choose a acticity that you want]

Fill in the details of the New Android Activity and click Finish.

0

If you want to see your new Activity's XML representation, you can go to the AndroidManifest.xml file.

You will see your Activity like so:

...

<activity android:name=".MyExerciseActivity"
        android:label="My Exercise Chart"
        android:parentActivityName=".MainActivity"
        />
<activity android:name=".MainActivity">

...

0

Add new Activity

Select package -> File -> New -> Activity
0

Right-click on the package or directory, then select new kotlin or java

enter image description here

when new kotlin class or file you can choice What kind of class

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.