Best way to add Activity to an Android project in Eclipse?

When adding an activity to an existing Android project, I manually create a new class - is that the best / preferred way?

How do others handle that?



You can use the "New Class" dialog, but that leaves other steps you need to do by hand (e.g. adding an entry to the manifest file). If you want those steps to be automated, you can create the activity via the manifest editor like this:


  1. Double click on AndroidManifest.xml in the package explorer.

  2. Click on the "Application" tab of the manifest editor

  3. Click on "Add.." under the "Application Nodes" heading (bottom left of the screen)

  4. Choose Activity from the list in the dialog that pops up (if you have the option, you want to create a new top-level element)

  5. Click on the "Name*" link under the "Attributes for" header (bottom right of the window) to create a class for the new activity.


When you click Finish from the new class dialog, it'll take you to your new activity class so you can start coding.


Five steps might seem a lot, but I'm just trying to be extra detailed here so that it's clear. It's pretty quick when you actually do it.





One caveat is that you must remember to prepend the "." to your Activitiy name, or you will end up with all sorts of nonsensical err msgs. – Clay Shannon Dec 3 '11 at 21:59

I tried doing this with Eclipse 3.5.2 on Ubuntu 10.04. When the add dialog comes up, it has two selections... No, now only one "Create a new element at the top level, in Application." Ne;low that there is a text entry field and below that, a box with selections for Activity, Activity Alias, Meta Data and so on. Below that there are buttons for "Cancel" and "OK". Upon the first character entered in the text field, all selections disappear and the "OK" button becomes gray. Bug or am I doing it wrong?



Thx, hank – HankB





مواضيع متعلقة


اهم الفاعليات لهذا الشهر


الشبكات الإجتماعية

تغريدات تويتر