gpt4 book ai didi

java - getSerializableExtra 返回 null

转载 作者:太空宇宙 更新时间:2023-11-03 13:27:37 25 4
gpt4 key购买 nike

我的例子:

public static final String EXTRA_TARGET_FRAGMENT = "fragment_to_show";

public static void show(Activity pActivity,
Class<? extends Fragment> fragment) {
Intent intent = new Intent(pActivity, HomeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra(EXTRA_TARGET_FRAGMENT, fragment);
pActivity.startActivity(intent);
}

@SuppressWarnings("unchecked")
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
setIntent(intent);
mUpcomingTarget = (Class<Fragment>) intent
.getSerializableExtra(EXTRA_TARGET_FRAGMENT);

}

mUpcomingTarget --> null,我不明白这是什么问题。

最佳答案

putExtra(String, Serializable) 的文档说

The name must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".

将您的 EXTRA_TARGET_FRAGMENT 更改为以包前缀开头。

关于java - getSerializableExtra 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17293791/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com