Christian Gardner
Christian Gardner

Reputation: 267

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.

Upvotes: 11

Views: 36442

Answers (4)

Andrew Marin
Andrew Marin

Reputation: 1083

For those, who come from Google, I was trying to pass large string in putExtra (over 90K Symbols) and my app was crashing because of that. The correct solution is either save the string to file or implement Singleton.

Here is the relevant link Maximum length of Intent putExtra method? (Force close)

Upvotes: 5

Dhaval Parmar
Dhaval Parmar

Reputation: 18978

as per your code: if i have create newActiviy in my project then:

i have to add that activity in android manifest file.

like:

<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 android:name=".newActivity"></activity>
</activity>

for calling that activity just do:

Intent intent = new Intent(MainActivity.this, newActivity.class);
    startActivity(intent);

befre ask question here try some googling. and you must have to check this: Building Your First Android App and Starting Another Activity

Upvotes: 2

krishna
krishna

Reputation: 998

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>

Upvotes: 28

Shiv
Shiv

Reputation: 4567

Start new Activity like this:

Intent intent = new Intent(YourCurrentActivity.this, TargetActivity.class);
    startActivity(intent);

Upvotes: 0

Related Questions