0

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


David Wasser
  • 93,459
  • 16
  • 209
  • 274
kellogs
  • 2,837
  • 3
  • 38
  • 51
  • possibly related: http://stackoverflow.com/questions/11703256/android-activity-intent-remains-after-shutdown – kellogs Sep 22 '12 at 14:13

1 Answers1

0

I have managed to overcome the problem by mistake, it seems: The docs mention that Activities are to be destroyed / re-created on various events, such as Configuration changes. So I thought of stealing control form the OS on all configuration changes possible; now AndroidManifest.xml looks like

<activity android:name=".ui.MainMenu" android:launchMode="singleTop" android:screenOrientation="reverseLandscape" android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
   android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|fontScale"   />

... etc, same for all activities

Now, the docs also state that:

public void onConfigurationChanged (Configuration newConfig) Since: API Level 1

Called by the system when the device configuration changes while your activity is running. Note that this will only be called if you have selected configurations you would like to handle with the configChanges attribute in your manifest. If any configuration change occurs that is not selected to be reported by that attribute, then instead of reporting it the system will stop and restart the activity (to have it launched with the new configuration).

I did override this method in my activities and it seldom gets called at all (like, 1 in 20 times maybe). But the problem is gone, and this method does not really get called. So I amkind of confused. Maybe this was not at the bottom of my issue but.. somehow related.

kellogs
  • 2,837
  • 3
  • 38
  • 51