我的例子:
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/