在android中从bundle获取id的问题



我在第二个活动中获取id时遇到问题,我在第一个活动中以如下方式在捆绑包中传递id

Bundle bundle = new Bundle();
bundle.putInt(Constants.ID, featured.getId());
bundle.putString(Constants.TITLE, "Team");
openAcitivty(getBundle("Questions" , (Serializable) featured.getAll().getQa()) , ProviderQAactivity.class );

但是当我在第二个活动中获得id时,它在这里显示为零

uid = getIntent().getBundleExtra(Constants.DATA).getInt(Constants.ID);

请提出一些建议。

尝试

getIntent().getExtras().getInt(Constants.ID)
getIntent().getExtras().getString(Constants.TITLE)

可能会解决你的问题。

还让我们知道下面函数的内部内容。您是否通过意向将捆绑包正确地传递给下一个活动。

`openAcitivty(getBundle("Questions" , (Serializable) featured.getAll().getQa()) , ProviderQAactivity.class );`

它必须包含一些代码

intent.putExtras(bundle);

试试这种方法。。

uid = getIntent().getExtras().getInt(Constants.ID);

当在行下调用时,它给出bundle对象。

Bundle bundle = getIntent().getExtras();

最新更新