0

I want to start my MainActivity, in android 2.3, it will not start, but in Jelly Bean it works. I get no error, nothing happens!

I've noticed when I use putExtra, then it does not work. Is there a reason?

start MainActivity

final ComponentName cn = new ComponentName("de.application.ui", "de.application.ui.MainActivity");

    Intent intent = IntentCompat.makeRestartActivityTask(cn);
    intent.putExtra("de.application.exit", true); // I have this line in it yet
    activity.startActivity(intent);

Manifest

<activity
        android:theme="@style/Theme"
        android:name=".ui.MainActivity"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>

My solution that works.

start MainActivity

   Intent intent = new Intent(activity, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("de.application.exit", true);
    activity.finish();
    activity.startActivity(intent);

Manifest

<activity
        android:theme="@style/Theme"
        android:name=".ui.MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
user949884
  • 503
  • 1
  • 8
  • 15

2 Answers2

0

I do this to start a main activity:

Intent intent = IntentCompat.makeRestartActivityTask(cn);
activity.startActivity(intent);


        Intent i =  new Intent("android.intent.action.MAIN");
        final ComponentName cn = new ComponentName  ("de.application.ui", "de.application.ui.MainActivity");

                        i.setComponent(n);                          

                    try {
                        startActivity(i);
                    } 
                    catch (ActivityNotFoundException e) {

                    }
Gyonder
  • 3,674
  • 7
  • 32
  • 49
0

Might want to give this a try:

    Intent intent = new Intent("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    intent.setComponent(new ComponentName("de.application.ui", "de.application.ui.MainActivity"));
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra("de.application.exit", true);
    startActivity(intent);
lucian.pantelimon
  • 3,673
  • 4
  • 29
  • 46
  • I see that you are using `makeRestartActivityTask`. Just checked the documentation for `Intent` and you might want to use `FLAG_ACTIVITY_CLEAR_TASK` as a flag. Let me know if it works and I'll update my answer afterward. – lucian.pantelimon Mar 07 '13 at 14:59
  • I've added the `putExtra` call to my answer. I've tested similar code (same function calls, same order, but the function calls to the `Intent` object were made with different parameters) on Android 2.2.1 (Sony-Ericsson Xperia Ray) and 4.2.2 (Nexus 7) and it worked fine... The issue shouldn't be in the function call i.m.o.. – lucian.pantelimon Mar 07 '13 at 15:59