简体   繁体   English

Intent Extras仅在某些设备上有效

[英]Intent extras only work on some devices

In my app I send some intent extras from one activity to another. 在我的应用程序中,我将一些意图额外的东西从一项活动发送到另一项活动。 But some users report back that these data are always zero - even though I can see the values are alright in the sending activity. 但是有些用户报告说这些数据始终为零-尽管我可以看到发送活动中的值还可以。

Here's the code of the sending activity: 这是发送活动的代码:

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);

And this is how it's read in the new activity: 这就是在新活动中的读取方式:

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;
}

On both my devices it works fine, but I have 3 cases of customers complaining that it doesn't work (documented in video recordings). 在我的两台设备上都可以正常工作,但是有3个客户抱怨它不起作用(记录在录像中)。

Any suggestions? 有什么建议么?

I tried to change the code to use getFloatExtra() instead of getString and parse it to a float, and it solved the problem. 我试图将代码更改为使用getFloatExtra()而不是getString并将其解析为浮点数,从而解决了该问题。 I see this is a lot more efficient, but I still don't understand why the original solution worked on some devices but not on others. 我看到这要高效得多,但是我仍然不明白为什么原始解决方案在某些设备上有效,而在另一些设备上无效。

Case closed! 结案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM