我的包为包含的额外内容返回空字符串。不是 NPE,是实际的“空”值。关于为什么会发生这种情况的任何想法?
新 bundle
String u = null;
Bundle b = new Bundle();
Intent i = new Intent(view.getContext(), ******.class);
u = api.companyData.link.get(position);
Log.d("URL++++++++++++++++++++", u);
b.putString("graphic", api.companyData.graphic);
b.putString("name", api.companyData.name);
b.putString("url", u);
i.putExtras(b);
startActivity(i);
日志语句返回 url 正常。
包的接收者
Bundle extras = getIntent().getExtras();
if(extras !=null) {
Log.d("EXTRAS", extras.getString("name")+extras.getString("graphic")+extras.getString("link"));
D/EXTRAS(4698):nullnullnull
最佳答案
我总是这样做:
Intent i = new Intent(view.getContext(), ******.class);
i.putExtra("url", u);
然后
String url = getIntent().getStringExtra("url");
我从来没有按照你的方式尝试过,但如果你 look at the Android docs对于 putExtras(Bundle)
,它说:
Add a set of extended data to the intent. The keys must include a package prefix, for example the app com.android.contacts would use names like "com.android.contacts.ShowAll".
您没有这样做可能是失败的原因。
关于Java extras 包返回空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11278243/