In my app there is an activity with alias: MyActivity and MyAliasActivity registered in the Manifest. The purpose of the alias is to provide extra intent filter. This feature can be enabled/disabled in the runtime by the user. The activity and alias has got singleTop modifier.
However, if I start my app with the component disabled (MyActivity on the top), then I enable it, and broadcast the event matching the intent filter, MyActivity is created one more time (by the alias)- I've got two of them in the backstack which is undesired.
Can it he handled in any way? I need to have only one activity in the backstack.
You should use
singleTaskinstead ofsingleTop.singleTaskwill guarantee that you only have one instance of an Activity in the backStack. In case you start an Activity for the second time withsingleTasklaunchMode, theonNewIntentwill be ran instead of creating a new Activity. Another solution is to usesingleInstance, this works pretty much the same assingleTask, keeping only one instance of Activity and runningonNewIntentif it is already created.For more information here is a good explanation of how it works:
https://inthecheesefactory.com/blog/understand-android-activity-launchmode/en
Google reference:
https://developer.android.com/guide/topics/manifest/activity-element.html