In my android app, I wanted to start an activity 'B' from initial activity 'A'. I have created classes for both of these. However when using following code to start B, I get a runtime error: application has stopped unexpectedly, try again
. Here is my code:
Intent myIntent = new Intent(this, AddNewActivity.class);
startActivity(myIntent);
When I added a new entry in AndroidManifest.xml/manifest/application/activity/intent-filers
for activity B then the application worked.
I have two questions:
AndroidManifest.xml
, how does android know which activity to start first?Here is my partial AndroidManifest.xml
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ListAllActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".AddNewActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
When there are multiple activities entries in AndroidManifest.xml, how does android know which activity to start first?
There is no "first". In your case, with your manifest as shown, you will have two icons in your launcher. Whichever one the user taps on is the one that gets launched.
I could not understand intent-filters. Can anyone please explain.
There is quite a bit of documentation on the subject. Please consider reading that, then asking more specific questions.
Also, when you get "application has stopped unexpectedly, try again", use adb logcat
, DDMS, or the DDMS perspective in Eclipse to examine the Java stack trace associated with the error.