Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How To Add Second Activity In Android

Hey everyone! Im trying to add a second activity to my android project, but im not sure how to add the activity files exactly?

Ive added a class here "Name/Scr/PackageName/MyClassHere" but Im not sure if that the correct thing to do or place to put it, because there isnt a XML file either.

Im using this code to open a new screen, http://learnandroid.blogspot.com/2008/01/opening-new-screen-in-android.html And I get 2 error's. 1 at runtimeon this line: Intent i = new Intent(Coinparison.this, ResultsScreen.class); it says it cant find my activity.

And the other error here setContentView(R.layout.ResultsScreen); which says "ResultsScreen" cannot be resolved.

Not sure whats wrong, but any help is great! :)

like image 918
Tanner.R Avatar asked Jun 06 '11 14:06

Tanner.R


People also ask

Can an app have multiple activities?

Most apps contain multiple screens, which means they comprise multiple activities. Typically, one activity in an app is specified as the main activity, which is the first screen to appear when the user launches the app. Each activity can then start another activity in order to perform different actions.


2 Answers

There is a wizard in eclipse now for adding activities, just right click on your project, go to new -> other -> android -> Android Activity

This will create the class, layout and manifest entry.

like image 125
Damon Smith Avatar answered Oct 17 '22 23:10

Damon Smith


Add your activity to AndroidManifest.xml

<activity android:name="ResultsScreen"
   android:label="@string/app_name">
   <intent-filter>
       <action android:name="android.intent.action.VIEW" />
   </intent-filter>
</activity>
like image 30
mysuperass Avatar answered Oct 17 '22 23:10

mysuperass