Reputation: 479
I use short cut to start an activity with an action and parameters.
fun makeShortcut(id: String, @StringRes shortLabel: Int, @StringRes longLabel: Int,
@DrawableRes icon: Int, action: String, cmd: String): ShortcutInfo {
return ShortcutInfo.Builder(context(), id)
.setShortLabel(context().getString(shortLabel))
.setLongLabel(context().getString(longLabel))
.setIcon(Icon.createWithResource(context(), icon))
.setIntents(arrayOf(
Intent(action).putExtra(KEY_CMD, cmd)
))
.build()
}
After starting the activity, I do some stuff and finish the activity. The I launch the activity from task manager. The value passed by KEY_CMD is still exists. I want to clear the values when activity enter from task manager.
Upvotes: 1
Views: 55
Reputation: 95628
This is either a bug or a feature of Android, depending on how you expect things to work. For you it obviously is more of a bug than a feature. See my detailed analysis of a similar question here
To solve your problem you could try creating an <activity-alias>
that you use for the shortcut. The <activity-alias>
points to the same <activity>
that you use as your main launcher, but you can specify different flags and behaviour. If you specify android:excludeFromRecents="true"
in the <activity-alias>
and use the <activity-alias>
in your shortcut, this should solve your problem.
If your entire application contains only one single Activity
, then you could probably easily solve your problem by adding android:excludeFromRecents="true"
for your Activity
in the manifest (in this case you don't need the <activity-alias>
).
Upvotes: 1