Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android app crashing on startActivity()

I have started an Intent and asked it to go to the main activity, when it attempts it the app crashes.

Here is the code that tries to go to the main activity.

Intent i = new Intent(
".MAIN_ACTIVITY");
startActivity(i);   

Here is the XML manifest for Main_Activity.

<activity
    android:name=".MainActivity"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN_ACTIVITY" />

        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
</activity>

I'm still pretty new to this so any help and/or advice is of great value.

like image 220
Christian Gardner Avatar asked Apr 05 '13 13:04

Christian Gardner


1 Answers

Write like this :

Intent i = new Intent(MainActivity.this, NewActivity.class);
startActivity(i);

Also you need to declare both activity class in manifest file like this:

<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
    <action android:name="android.intent.action.MAIN_ACTIVITY" />

    <category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
    android:name=".NewActivity"
    android:label="@string/app_name" >
</activity>
like image 134
krishna Avatar answered Oct 17 '22 07:10

krishna