Android:从“最近”选项卡打开应用程序时保留来自共享 ACTION_SEND 的数据

Android : Data from shared ACTION_SEND retained when open app from Recent tab

我的应用程序正在订阅来自另一个应用程序的传入 ACTION_SEND 数据。

当我将来自另一个应用程序的文本分享到我的应用程序时,它也能正常工作。 但是如果完成我的应用程序然后从“最近”选项卡重新打开它,ACTION_SEND 数据会继续保留。

我希望在我的应用程序完成后清除共享数据。如何解决?

这是我的代码片段:

if (Intent.ACTION_SEND == action && type != null) {
    if ("text/plain" == type) {
        val sharedText = intent.getStringExtra(Intent.EXTRA_TEXT)
        if (sharedText != null && URLUtil.isValidUrl(sharedText)) {
            sharedUrl = sharedText
        }
    }
}

您看到的是这个现象:

链接的问题与 Intent 中的“extras”相关,但行为是相同的。我已经解释了发生了什么,并提供了一些选项来解决链接答案中的问题。