androidandroid-activityandroid-homebutton

Activity ends on HOME button


I have weird problem with HOME button. I have two activities A and B.

A always starts B...like this:

startActivityForResult(new Intent("com.test.B"), 0);

and listening for result for finishing the whole app...but that i think doesn't matter.

When I'm in B activity, and hit the HOME button...and on long press of HOME button get back. Activity A is shown instead of B...

Why is that happening? Any idea? Should I set something in Manifest? It looks to like activity B is finished...but i dont want that. I want B to be shown...

Here is some code from A activity:

// Start new activity
Intent intent = new Intent(getApplicationContext(),B.class);
startActivityForResult(intent, 0);

And here is some code from manifest:

<activity
        android:label="A"
        android:name=".A"
        android:screenOrientation="portrait" >
        <intent-filter >
            <action android:name="com.uno_manager.A" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:label="B"
        android:name=".B"
        android:noHistory="true"
        android:screenOrientation="portrait" >
        <intent-filter >
            <action android:name="com.uno_manager.B" />

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

I have activity one activity before those two...that represents splash screen.

In activity B I have overridden onRestoreInstance and onInstanceSave methods. And on some click I call setResult and finish() to exit the app. But I don't think that have anything to do with this.

I've tried to comment whole code from B activity. I've left only setContentView in onCreate method. And the same thing happened on HOME button.


Solution

  • In your manifest file add launchMode attributes to your activities. See this link for more information to reuse http://developer.android.com/guide/topics/manifest/activity-element.html#lmode

    I think anything apart from standard would work for your requirement, but see the documentation for full information or experiment with them to find out the correct one