I have a quit method that does this:
public void quitFinalize(ServicedActivity actCtx)
{
for (ServicedActivity act : mRunningActivities)
launchActivity(actCtx, new Intent(mAppCtx, act.getClass()).setAction("--"));
}
Checked that the mRunningActivities is OK.It consists of all activities in my task that were created and not destroyed. All the activities inherit from :
public class ServicedActivity extends FragmentActivity implements OnClickListener
{
...
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
if (/*Intent.ACTION_SCREEN_OFF*/"--".equals(intent.getAction())) // used for quitting the game
{
finish();
}
}
...
}
I have noticed that for 2 activities in the Set, the mechanism works fine. For 3 activities however, Android 4.0.3 decides that it should launch (create) another instance of one of the activities in the Set (it seems it especially likes to start one certain Activity, not just any). and them finish them all (thus 4 destroyed activities instead of the original 3)
I am certain it is not me creating that activity inadvertently - all my launchActivity logic is filtered through a method which appends the FLAG_ACTIVITY_REORDER_TO_FRONT flag to the Intent, so I can not end up with two instances of the same Activity class. It must be the OS who's creating it anew.
Also tried without the 'android:launchMode="singleTop"' manifest file property - it is like this for all the Activities in the app. Same thing.
What is going on here ? the onNewIntent() method above gets hit 3 times as expected, yet in the middle, Android creates a new Activity then immediately terminates it too.
Thanks