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! :)
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.
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>
i think u need add this activity in manifest file like this
<application balblabla>
<activity android:name=".firstActivity">
android:label="@string/app_name"
//bla bla bla
</activity>
<activity android:name=".secondActivity"/>
</application>
see link again and find this : //AndroidManifest.xml
there u can see text which writed in bold mode
<activity class=".Screen2" android:label="Screen 2">
</activity>
Answer for Error in """ setContentView(R.layout.ResultsScreen);
which says "ResultsScreen
" cannot be resolved """
Go to second.java
(Related to second activity) file and import missing classes.
In Eclipse, press Ctrl + Shift + O to import missing classes (Cmd + Shift + O on Mac).
Here is a wizard in Android Studio now for adding New Activity, just right click on your project, go to new -> Application Name ->Select Phone and Tablet -> Select Minimum API Level->Next->Blank Activity->Next->Activity Name->Next-> Finish
This will create the class, layout and manifest entry.