![](/img/trans.png)
[英]Getting null while passing data through a bundle from Activity to Fragment
[英]Getting Null Values while passing data with intent from adapter to activity
这可能是一个非常基本的问题,但我找不到答案。
我需要从RecyclerView传递数据,但是当我在相关活动中检查数据时,数据为null。
mvHolder.barcode.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent s = new Intent(context, SummaryActivity.class);
s.putExtra("SUMMARY",sp.getDATA().get(i).getId_summary()); // data is not null
context.startActivity(s);
}
});
这就是我尝试实现的方法:
Bundle extras = getIntent().getExtras();
if (extras != null) {
strBarcode = extras.getString("SUMMARY");
// and get whatever type user account id is
}
但是当我调试它时,结果发现strBarcode为null。 我不知道问题出在哪里,我想我的代码也应该可行。 请帮我
Intent data = getIntent();
if (data != null) {
strBarcode = data.getStringExtra("SUMMARY");
// and get whatever type user account id is
}
检查getIntent().hasExtra("SUMMARY") returns true
。 如果是这样,请确保sp.getDATA().get(i).getId_summary()
返回String
。
可能有多余的东西,但是您尝试将其作为String获取,并且它可能具有不同的类型。
Intent data = getIntent();
if (data != null) {
int strBarcode = data.getIntExtra("SUMMARY");
}
请试试这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.