Android: Starting app from 'recent applications' starts it with the last set of extras used in an intent

后端 未结 3 1321
刺人心
刺人心 2020-12-06 05:27

Bit of a confusing problem for me here:

I\'ve got a home screen widget which, when clicked, starts my main app Activity with a few extras put in the intent:

3条回答
  •  囚心锁ツ
    2020-12-06 06:27

    I think you can distinguish a "normal" startup from a "recent applications" startup by checking the Intent flags; there is a flag called

    Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY

    which, according to the documentation:

    This flag is not normally set by application code, but set for you by the system if this activity is being launched from history (longpress home key).

    So when this flag is set, you could choose to ignore the extras.

提交回复
热议问题