Android - 第二次调用 onCreate() 后 Bundle 不为空

Android - Bundle is not null after second call of onCreate()

我有一个非常奇怪的问题...如果我在我的 nexus 5 上调用代码,我会得到一个 bundle(Bundle[mParcelledData.dataSize=36] ???) 但 bundle 应该是空的!它只是在我的 nexus 5 上,在其他设备上,方法 intent.getExtra() 为空!

有什么解决这个问题的建议吗?

        Bundle extras = getIntent().getExtras();
    if(extras != null) {
        String test = extras.toString();
        Toast.makeText(this, "why??! " + test, Toast.LENGTH_LONG).show(); }

我第二次打开应用程序时,extra 不是空的,它是 Bundle[mParcelledData.dataSize=36]。这里有什么问题吗?

您可以迭代键集以查看添加到包中的内容。看看 Nexus 上的捆绑 returns 上的 isEmpty() 是什么也可能很有趣。

如果您正在检查已添加到意图的额外内容,您的 null 可能适用于大多数设备。如果捆绑包不为空,(Nexus 解决方法)您可能必须添加二次检查以查看您期望的密钥是否存在。