Very strange thing here.
I initially had an activity that was the start up activity (Activity A). It had the tag android:launchMode="singleTask" associated with it. No problems. My requirements changed and now i’m making Activity B the startup activity. I copied the intent filter over, I changed the name to “.ActivityB” and I moved the launch mode tag over as well.
It seems to work okay; when I start the app I go to Activity B. However when I go from Activity B to Activity A and then click the back button the app exits and won’t reopen (it will reopen if I don’t have the launch mode tag.)
Another example. If I go from Activity A to Activity B to Activity A to Activity B everything is fine. When I click back i go to Activity A (as expected) however when I click back again I go to a previous instance of Activity A (uh oh) then I click back again and exit the app. Both times skipping Activity B.
I’m clearly overlooking something but I can’t figure out what. I’m not overriding any back button functionality and everything worked perfectly before I switched the start up activity.
Edit
The following is an excerpt from my manifest before any change
<activity android:name=".ActivityA" android:windowSoftInputMode="stateHidden" android:label="@string/app_name" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ActivityB"></activity>
Here is an excerpt after the change
<activity android:name=".ActivityB" android:windowSoftInputMode="stateHidden" android:label="@string/app_name" android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ActivityA"></activity>
Sounds like Activity B is getting
finish()called or something. I suggest putting in some log statements inOnCreate,OnPause,OnResume, andOnDestroyso you can monitor the life of Activity B. Its a highlander activity (there can only be 1) so you don’t have to worry about multiple instances being created. Also you might look into / overrideonNewIntentand placing some logging calls there.Not really an answer, but dollars to donuts you or someone put a
finish()call after starting Activity A, or when Activity B goes in the background and you’ve forgotten about it.If that’s not the case I’d be interested in how/when Activity B dies. Usually if it stops because of some error upon returning to it, Android will bark at you but since you didn’t mention that I’d guess it isn’t.