Nick
Nick

Reputation: 3435

Android activities launch behavior

My app has two activities. Activity A is the main activity and it has

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

in the manifest. I do not set any android:launchMode for A. Activity A launches Activity B. I press home button in activity B and return to Android menu. If I press my app icon in Android menu, would it launch new instance of activity A or return back to B?

I can see it returns back to activity B and I do not understand why. As I did not set android:launchMode, it should launch new instance of A every time I press icon, shouldn't it?

Upvotes: 0

Views: 44

Answers (1)

BVB
BVB

Reputation: 5420

Activity B launches because when you press your Home button, the application is not "closed", but merely sent to the background. Such is the workflow of Android. If you want to finish Activity B when it is sent to the background, you can call this.finish() in an overridden onPause() function in Activity B.

For more information on managing the Activity lifecycle, check out this very useful tutorial: http://developer.android.com/training/basics/activity-lifecycle/index.html

Upvotes: 2

Related Questions