How to add new activity to existing project in Android Studio?

AndroidAndroid Studio

Android Problem Overview


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.

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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

enter image description here

Solution 3 - Android

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.

Solution 4 - Android

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.

Solution 5 - Android

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.

Solution 6 - Android

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">

...

Solution 7 - Android

Add new Activity

Select package -> File -> New -> Activity

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHaşim ŞemdinoğluView Question on Stackoverflow
Solution 1 - AndroidGlennView Answer on Stackoverflow
Solution 2 - AndroidMajidView Answer on Stackoverflow
Solution 3 - AndroidVinceStylingView Answer on Stackoverflow
Solution 4 - AndroidPalak JainView Answer on Stackoverflow
Solution 5 - AndroidSanoob PookodanView Answer on Stackoverflow
Solution 6 - AndroidWilliam ParrishView Answer on Stackoverflow
Solution 7 - AndroidyoAlex5View Answer on Stackoverflow