[英]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.