Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>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:</p> <p>A new <code>Activity</code> in Eclipse is actually a <code>Class</code>.</p> <p>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 <code>Name</code> as <code>NewActivity</code> and set the <code>Superclass</code> to <code>android.app.Activity</code>, then hit Finish. </p> <p>When the NewActivity.java file opens up it should look like this:</p> <pre><code>package com.example.yourappname; import android.app.Activity; public class NewActivity extends Activity { } </code></pre> <p>You can leave the <code>Superclass</code> blank and add <code>extends Activity</code> to the code itself if you prefer.</p> <p>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'.</p> <p>And then you can add your <code>onCreate()</code> code so it looks like this:</p> <pre><code>public class NewActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main_view); //rest of the code } } </code></pre> <p><code>main_view</code> would be your main view xml file, <code>main_view.xml</code>, that you would create in your layout directory.</p> <p>To call the new Activity, your <code>Intent</code> in the code (in a different Activity) to start a new <code>Activity</code> looks something like this:</p> <pre><code>Intent startNewActivityOpen = new Intent(PresentActivity.this, NewActivity.class); startActivityForResult(startNewActivityOpen, 0); </code></pre> <p>And that's it, you have the code to call the new activity and you created it. I hope this helps someone.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload