[英]Intent extras only work on some devices
在我的应用程序中,我将一些意图额外的东西从一项活动发送到另一项活动。 但是有些用户报告说这些数据始终为零-尽管我可以看到发送活动中的值还可以。
这是发送活动的代码:
Intent intent = new Intent();
intent.setClass(waypointListView.this, addWaypointActivity.class);
intent.putExtra("latitude", String.format("%9.6f", globLatitude));
intent.putExtra("longitude", String.format("%9.6f", globLongitude));
startActivityForResult(intent, ACTIVITY_ADD_WAYPOINT);
这就是在新活动中的读取方式:
Intent myIntent = getIntent();
String latitudeStr = myIntent.getExtras().getString("latitude");
try{
globLatitude = Float.parseFloat(latitudeStr);
} catch(NumberFormatException nfe) {
globLatitude=0f;
}
String longitudeStr = myIntent.getExtras().getString("longitude");
try{
globLongitude = Float.parseFloat(longitudeStr);
} catch(NumberFormatException nfe) {
globLongitude=0f;
}
在我的两台设备上都可以正常工作,但是有3个客户抱怨它不起作用(记录在录像中)。
有什么建议么?
我试图将代码更改为使用getFloatExtra()而不是getString并将其解析为浮点数,从而解决了该问题。 我看到这要高效得多,但是我仍然不明白为什么原始解决方案在某些设备上有效,而在另一些设备上无效。
结案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.