App Closes after calling setComponentEnabledSetting for using Activity Alias
Your Activity is being closed probably because you have enabled/disabled your target Activity. Note that the App (Application Process) has not been killed. Anyways this is what I did to stop the Activity from closing:
In general you want to do the following:
- Use just activity-aliases for icons
- Remove the category "launcher" from the target Activity
- Only enable/disable activity-aliases
Your AndroidManifest.xml should look something like this:
<activity android:name=".MainActivity" ... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity-alias android:name=".No-Icon-Badge"
android:targetActivity=".MainActivity"
android:enabled="true"
... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:name=".Icon-Badge-1"
android:targetActivity=".MainActivity"
android:enabled="false"
... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
<activity-alias android:name=".Icon-Badge-2"
android:targetActivity=".MainActivity"
android:enabled="false"
... >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity-alias>
...
So your MainActivity is enabled (keep it that way), but has no LAUNCHER category so it won't show up. Also the first activity-alias is enabled (this is your default) and all the other ones are disabled.
Good luck!