Ok. Being a newbie myself I think the above two answers are thinking too much. He's asking very simply how to create a new activity in Eclipse.. I think this is what he wants:
A new Activity
in Eclipse is actually a Class
, so if your Intent
in the code to start a new Activity
looks something like this:
Intent startNewActivityOpen = new Intent(PresentActivity.this, NewActivity.class);
startActivityForResult(startNewActivityOpen, 0);
You would doubleclick 'src' on the left side in the Package Explorer, then highlight your 'com.' name, right click, select 'New' and then select 'Class'. Enter the name as 'NewActivity' to match the code above and hit Finish. When the NewActivity.java file opens up just add 'extends Activity' so it looks like this:
public class NewActivity extends Activity {
}
The final step is adding the Activity to your Manifest. So doubleclick AndroidManifest.xml to open it up and then click the 'Application' tab on the bottom. Next to the 'Application Nodes' box, click 'Add'. Highlight 'Activity' (the square box with a capital A) and click 'Ok'. Now look for the 'Attributes for Activity' box and enter a Name for the Activity and precede it by a period. In this example you'd enter '.NewActivity'.
And then you can add your onCreate()
code so it looks like this:
public class NewActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_view);
}
}
main_view
would be your main view xml file, main_view.xml
, that you would create in your layout directory.
And that's it, you have the code to call the new activity and you created it. I hope this helps someone.