是的,我知道有意图地传递数据非常简单,但是突然不起作用。多余的数据始终为空。
有人可以告诉我为什么...因为我看不到任何错误。
我可以调试代码,当它在startActivity(intent)
中时,我可以看到该意图已正确设置了额外的数据。当我停止getIntent().getExtras()
中的代码时,还会丢失额外的数据
活动A
Intent intent = new Intent(mActivity, ScreenActivity.class);
intent.putExtra(ArgumentsNamesConfig.IS_PUSH_NOTIFICATION, true);
intent.putExtra(ArgumentsNamesConfig.ARG_ARTICLE, article);
intent.putExtra(MyFirebaseMessagingService.IS_GEO_NOTIFICATION, isGeoNotification);
mActivity.startActivity(intent);
ScreenActivity.class
(进入onCreate方法)
Intent intent = getIntent();
pushNotificationProductId = intent.getBooleanExtra(ArgumentsNamesConfig.IS_PUSH_NOTIFICATION);
isGeoNotification = intent.getBooleanExtra(MyFirebaseMessagingService.IS_GEO_NOTIFICATION, false);
mArticle = intent.getParcelable(ArgumentsNamesConfig.ARG_ARTICLE);
答案 0 :(得分:0)
intent.putExtra(ArgumentsNamesConfig.IS_PUSH_NOTIFICATION,true);是布尔值,并且您正在尝试将其获取为STRING(intent.getStringExtra(ArgumentsNamesConfig.IS_PUSH_NOTIFICATION)
尝试将游览代码更改为此
Intent intent = getIntent();
pushNotificationProductId = intent.getBooleanExtra(ArgumentsNamesConfig.IS_PUSH_NOTIFICATION);
isGeoNotification = intent.getBooleanExtra(MyFirebaseMessagingService.IS_GEO_NOTIFICATION, false);
mArticle = intent.getParcelable(ArgumentsNamesConfig.ARG_ARTICLE);